提交 a75aa90c 编写于 作者: J Jasmin Jessich 提交者: Mauro Carvalho Chehab

media: dvb_ca_en50221: Used a helper variable

Used a helper variable "struct dvb_ca_slot *sl" instead of
"ca->slot_info[slot]". This reduces the line length and simplifies
code reading.

Fixed also "-strict" checks in this patch:
- Comparison to NULL written as "!<var>".
Signed-off-by: NJasmin Jessich <jasmin@anw.at>
Signed-off-by: NMauro Carvalho Chehab <mchehab@s-opensource.com>
上级 bacba9e5
...@@ -234,13 +234,14 @@ static char *findstr(char *haystack, int hlen, char *needle, int nlen) ...@@ -234,13 +234,14 @@ static char *findstr(char *haystack, int hlen, char *needle, int nlen)
*/ */
static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private *ca, int slot) static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private *ca, int slot)
{ {
struct dvb_ca_slot *sl = &ca->slot_info[slot];
int slot_status; int slot_status;
int cam_present_now; int cam_present_now;
int cam_changed; int cam_changed;
/* IRQ mode */ /* IRQ mode */
if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) { if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) {
return (atomic_read(&ca->slot_info[slot].camchange_count) != 0); return (atomic_read(&sl->camchange_count) != 0);
} }
/* poll mode */ /* poll mode */
...@@ -249,22 +250,23 @@ static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private *ca, int slot) ...@@ -249,22 +250,23 @@ static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private *ca, int slot)
cam_present_now = (slot_status & DVB_CA_EN50221_POLL_CAM_PRESENT) ? 1 : 0; cam_present_now = (slot_status & DVB_CA_EN50221_POLL_CAM_PRESENT) ? 1 : 0;
cam_changed = (slot_status & DVB_CA_EN50221_POLL_CAM_CHANGED) ? 1 : 0; cam_changed = (slot_status & DVB_CA_EN50221_POLL_CAM_CHANGED) ? 1 : 0;
if (!cam_changed) { if (!cam_changed) {
int cam_present_old = (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE); int cam_present_old = (sl->slot_state != DVB_CA_SLOTSTATE_NONE);
cam_changed = (cam_present_now != cam_present_old); cam_changed = (cam_present_now != cam_present_old);
} }
if (cam_changed) { if (cam_changed) {
if (!cam_present_now) { if (!cam_present_now) {
ca->slot_info[slot].camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED; sl->camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED;
} else { } else {
ca->slot_info[slot].camchange_type = DVB_CA_EN50221_CAMCHANGE_INSERTED; sl->camchange_type = DVB_CA_EN50221_CAMCHANGE_INSERTED;
} }
atomic_set(&ca->slot_info[slot].camchange_count, 1); atomic_set(&sl->camchange_count, 1);
} else { } else {
if ((ca->slot_info[slot].slot_state == DVB_CA_SLOTSTATE_WAITREADY) && if ((sl->slot_state == DVB_CA_SLOTSTATE_WAITREADY) &&
(slot_status & DVB_CA_EN50221_POLL_CAM_READY)) { (slot_status & DVB_CA_EN50221_POLL_CAM_READY)) {
// move to validate state if reset is completed // move to validate state if reset is completed
ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_VALIDATE; sl->slot_state = DVB_CA_SLOTSTATE_VALIDATE;
} }
} }
...@@ -333,6 +335,7 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot, ...@@ -333,6 +335,7 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot,
*/ */
static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot) static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot)
{ {
struct dvb_ca_slot *sl = &ca->slot_info[slot];
int ret; int ret;
int buf_size; int buf_size;
u8 buf[2]; u8 buf[2];
...@@ -340,13 +343,13 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot) ...@@ -340,13 +343,13 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot)
dprintk("%s\n", __func__); dprintk("%s\n", __func__);
/* we'll be determining these during this function */ /* we'll be determining these during this function */
ca->slot_info[slot].da_irq_supported = 0; sl->da_irq_supported = 0;
/* /*
* set the host link buffer size temporarily. it will be overwritten * set the host link buffer size temporarily. it will be overwritten
* with the real negotiated size later. * with the real negotiated size later.
*/ */
ca->slot_info[slot].link_buf_size = 2; sl->link_buf_size = 2;
/* read the buffer size from the CAM */ /* read the buffer size from the CAM */
ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND,
...@@ -367,7 +370,7 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot) ...@@ -367,7 +370,7 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot)
buf_size = (buf[0] << 8) | buf[1]; buf_size = (buf[0] << 8) | buf[1];
if (buf_size > HOST_LINK_BUF_SIZE) if (buf_size > HOST_LINK_BUF_SIZE)
buf_size = HOST_LINK_BUF_SIZE; buf_size = HOST_LINK_BUF_SIZE;
ca->slot_info[slot].link_buf_size = buf_size; sl->link_buf_size = buf_size;
buf[0] = buf_size >> 8; buf[0] = buf_size >> 8;
buf[1] = buf_size & 0xff; buf[1] = buf_size & 0xff;
dprintk("Chosen link buffer size of %i\n", buf_size); dprintk("Chosen link buffer size of %i\n", buf_size);
...@@ -459,6 +462,7 @@ static int dvb_ca_en50221_read_tuple(struct dvb_ca_private *ca, int slot, ...@@ -459,6 +462,7 @@ static int dvb_ca_en50221_read_tuple(struct dvb_ca_private *ca, int slot,
*/ */
static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot) static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot)
{ {
struct dvb_ca_slot *sl;
int address = 0; int address = 0;
int tuple_length; int tuple_length;
int tuple_type; int tuple_type;
...@@ -531,10 +535,10 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot) ...@@ -531,10 +535,10 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot)
rasz = tuple[0] & 3; rasz = tuple[0] & 3;
if (tuple_length < (3 + rasz + 14)) if (tuple_length < (3 + rasz + 14))
return -EINVAL; return -EINVAL;
ca->slot_info[slot].config_base = 0; sl = &ca->slot_info[slot];
for (i = 0; i < rasz + 1; i++) { sl->config_base = 0;
ca->slot_info[slot].config_base |= (tuple[2 + i] << (8 * i)); for (i = 0; i < rasz + 1; i++)
} sl->config_base |= (tuple[2 + i] << (8 * i));
/* check it contains the correct DVB string */ /* check it contains the correct DVB string */
dvb_str = findstr((char *)tuple, tuple_length, "DVB_CI_V", 8); dvb_str = findstr((char *)tuple, tuple_length, "DVB_CI_V", 8);
...@@ -568,7 +572,7 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot) ...@@ -568,7 +572,7 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot)
break; break;
/* get the config option */ /* get the config option */
ca->slot_info[slot].config_option = tuple[0] & 0x3f; sl->config_option = tuple[0] & 0x3f;
/* OK, check it contains the correct strings */ /* OK, check it contains the correct strings */
if (!findstr((char *)tuple, tuple_length, if (!findstr((char *)tuple, tuple_length,
...@@ -598,8 +602,7 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot) ...@@ -598,8 +602,7 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot)
return -EINVAL; return -EINVAL;
dprintk("Valid DVB CAM detected MANID:%x DEVID:%x CONFIGBASE:0x%x CONFIGOPTION:0x%x\n", dprintk("Valid DVB CAM detected MANID:%x DEVID:%x CONFIGBASE:0x%x CONFIGOPTION:0x%x\n",
manfid, devid, ca->slot_info[slot].config_base, manfid, devid, sl->config_base, sl->config_option);
ca->slot_info[slot].config_option);
// success! // success!
return 0; return 0;
...@@ -614,19 +617,20 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot) ...@@ -614,19 +617,20 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private *ca, int slot)
*/ */
static int dvb_ca_en50221_set_configoption(struct dvb_ca_private *ca, int slot) static int dvb_ca_en50221_set_configoption(struct dvb_ca_private *ca, int slot)
{ {
struct dvb_ca_slot *sl = &ca->slot_info[slot];
int configoption; int configoption;
dprintk("%s\n", __func__); dprintk("%s\n", __func__);
/* set the config option */ /* set the config option */
ca->pub->write_attribute_mem(ca->pub, slot, ca->pub->write_attribute_mem(ca->pub, slot, sl->config_base,
ca->slot_info[slot].config_base, sl->config_option);
ca->slot_info[slot].config_option);
/* check it */ /* check it */
configoption = ca->pub->read_attribute_mem(ca->pub, slot, ca->slot_info[slot].config_base); configoption = ca->pub->read_attribute_mem(ca->pub, slot,
sl->config_base);
dprintk("Set configoption 0x%x, read configoption 0x%x\n", dprintk("Set configoption 0x%x, read configoption 0x%x\n",
ca->slot_info[slot].config_option, configoption & 0x3f); sl->config_option, configoption & 0x3f);
/* fine! */ /* fine! */
return 0; return 0;
...@@ -651,6 +655,7 @@ static int dvb_ca_en50221_set_configoption(struct dvb_ca_private *ca, int slot) ...@@ -651,6 +655,7 @@ static int dvb_ca_en50221_set_configoption(struct dvb_ca_private *ca, int slot)
static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
u8 *ebuf, int ecount) u8 *ebuf, int ecount)
{ {
struct dvb_ca_slot *sl = &ca->slot_info[slot];
int bytes_read; int bytes_read;
int status; int status;
u8 buf[HOST_LINK_BUF_SIZE]; u8 buf[HOST_LINK_BUF_SIZE];
...@@ -662,13 +667,13 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, ...@@ -662,13 +667,13 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
if (ebuf == NULL) { if (ebuf == NULL) {
int buf_free; int buf_free;
if (ca->slot_info[slot].rx_buffer.data == NULL) { if (!sl->rx_buffer.data) {
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
buf_free = dvb_ringbuffer_free(&ca->slot_info[slot].rx_buffer); buf_free = dvb_ringbuffer_free(&sl->rx_buffer);
if (buf_free < (ca->slot_info[slot].link_buf_size + if (buf_free < (sl->link_buf_size +
DVB_RINGBUFFER_PKTHDRSIZE)) { DVB_RINGBUFFER_PKTHDRSIZE)) {
status = -EAGAIN; status = -EAGAIN;
goto exit; goto exit;
...@@ -676,7 +681,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, ...@@ -676,7 +681,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
} }
if (ca->pub->read_data && if (ca->pub->read_data &&
(ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_LINKINIT)) { (sl->slot_state != DVB_CA_SLOTSTATE_LINKINIT)) {
if (ebuf == NULL) if (ebuf == NULL)
status = ca->pub->read_data(ca->pub, slot, buf, status = ca->pub->read_data(ca->pub, slot, buf,
sizeof(buf)); sizeof(buf));
...@@ -714,20 +719,18 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, ...@@ -714,20 +719,18 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
/* check it will fit */ /* check it will fit */
if (ebuf == NULL) { if (ebuf == NULL) {
if (bytes_read > ca->slot_info[slot].link_buf_size) { if (bytes_read > sl->link_buf_size) {
pr_err("dvb_ca adapter %d: CAM tried to send a buffer larger than the link buffer size (%i > %i)!\n", pr_err("dvb_ca adapter %d: CAM tried to send a buffer larger than the link buffer size (%i > %i)!\n",
ca->dvbdev->adapter->num, bytes_read, ca->dvbdev->adapter->num, bytes_read,
ca->slot_info[slot].link_buf_size); sl->link_buf_size);
ca->slot_info[slot].slot_state = sl->slot_state = DVB_CA_SLOTSTATE_LINKINIT;
DVB_CA_SLOTSTATE_LINKINIT;
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
if (bytes_read < 2) { if (bytes_read < 2) {
pr_err("dvb_ca adapter %d: CAM sent a buffer that was less than 2 bytes!\n", pr_err("dvb_ca adapter %d: CAM sent a buffer that was less than 2 bytes!\n",
ca->dvbdev->adapter->num); ca->dvbdev->adapter->num);
ca->slot_info[slot].slot_state = sl->slot_state = DVB_CA_SLOTSTATE_LINKINIT;
DVB_CA_SLOTSTATE_LINKINIT;
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
...@@ -758,8 +761,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, ...@@ -758,8 +761,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
if (status < 0) if (status < 0)
goto exit; goto exit;
if (status & STATUSREG_RE) { if (status & STATUSREG_RE) {
ca->slot_info[slot].slot_state = sl->slot_state = DVB_CA_SLOTSTATE_LINKINIT;
DVB_CA_SLOTSTATE_LINKINIT;
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
...@@ -767,11 +769,11 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, ...@@ -767,11 +769,11 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
/* OK, add it to the receive buffer, or copy into external buffer if supplied */ /* OK, add it to the receive buffer, or copy into external buffer if supplied */
if (ebuf == NULL) { if (ebuf == NULL) {
if (ca->slot_info[slot].rx_buffer.data == NULL) { if (!sl->rx_buffer.data) {
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
dvb_ringbuffer_pkt_write(&ca->slot_info[slot].rx_buffer, buf, bytes_read); dvb_ringbuffer_pkt_write(&sl->rx_buffer, buf, bytes_read);
} else { } else {
memcpy(ebuf, buf, bytes_read); memcpy(ebuf, buf, bytes_read);
} }
...@@ -805,6 +807,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, ...@@ -805,6 +807,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot, static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
u8 *buf, int bytes_write) u8 *buf, int bytes_write)
{ {
struct dvb_ca_slot *sl = &ca->slot_info[slot];
int status; int status;
int i; int i;
...@@ -812,11 +815,11 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot, ...@@ -812,11 +815,11 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
/* sanity check */ /* sanity check */
if (bytes_write > ca->slot_info[slot].link_buf_size) if (bytes_write > sl->link_buf_size)
return -EINVAL; return -EINVAL;
if (ca->pub->write_data && if (ca->pub->write_data &&
(ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_LINKINIT)) (sl->slot_state != DVB_CA_SLOTSTATE_LINKINIT))
return ca->pub->write_data(ca->pub, slot, buf, bytes_write); return ca->pub->write_data(ca->pub, slot, buf, bytes_write);
/* /*
...@@ -898,7 +901,7 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot, ...@@ -898,7 +901,7 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
if (status < 0) if (status < 0)
goto exit; goto exit;
if (status & STATUSREG_WE) { if (status & STATUSREG_WE) {
ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; sl->slot_state = DVB_CA_SLOTSTATE_LINKINIT;
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
...@@ -956,6 +959,7 @@ static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private *ca, int slot) ...@@ -956,6 +959,7 @@ static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private *ca, int slot)
void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int change_type) void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int change_type)
{ {
struct dvb_ca_private *ca = pubca->private; struct dvb_ca_private *ca = pubca->private;
struct dvb_ca_slot *sl = &ca->slot_info[slot];
dprintk("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type); dprintk("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type);
...@@ -968,8 +972,8 @@ void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int ch ...@@ -968,8 +972,8 @@ void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int ch
return; return;
} }
ca->slot_info[slot].camchange_type = change_type; sl->camchange_type = change_type;
atomic_inc(&ca->slot_info[slot].camchange_count); atomic_inc(&sl->camchange_count);
dvb_ca_en50221_thread_wakeup(ca); dvb_ca_en50221_thread_wakeup(ca);
} }
EXPORT_SYMBOL(dvb_ca_en50221_camchange_irq); EXPORT_SYMBOL(dvb_ca_en50221_camchange_irq);
...@@ -984,11 +988,12 @@ EXPORT_SYMBOL(dvb_ca_en50221_camchange_irq); ...@@ -984,11 +988,12 @@ EXPORT_SYMBOL(dvb_ca_en50221_camchange_irq);
void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221 *pubca, int slot) void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221 *pubca, int slot)
{ {
struct dvb_ca_private *ca = pubca->private; struct dvb_ca_private *ca = pubca->private;
struct dvb_ca_slot *sl = &ca->slot_info[slot];
dprintk("CAMREADY IRQ slot:%i\n", slot); dprintk("CAMREADY IRQ slot:%i\n", slot);
if (ca->slot_info[slot].slot_state == DVB_CA_SLOTSTATE_WAITREADY) { if (sl->slot_state == DVB_CA_SLOTSTATE_WAITREADY) {
ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_VALIDATE; sl->slot_state = DVB_CA_SLOTSTATE_VALIDATE;
dvb_ca_en50221_thread_wakeup(ca); dvb_ca_en50221_thread_wakeup(ca);
} }
} }
...@@ -1004,16 +1009,17 @@ EXPORT_SYMBOL(dvb_ca_en50221_camready_irq); ...@@ -1004,16 +1009,17 @@ EXPORT_SYMBOL(dvb_ca_en50221_camready_irq);
void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221 *pubca, int slot) void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221 *pubca, int slot)
{ {
struct dvb_ca_private *ca = pubca->private; struct dvb_ca_private *ca = pubca->private;
struct dvb_ca_slot *sl = &ca->slot_info[slot];
int flags; int flags;
dprintk("FR/DA IRQ slot:%i\n", slot); dprintk("FR/DA IRQ slot:%i\n", slot);
switch (ca->slot_info[slot].slot_state) { switch (sl->slot_state) {
case DVB_CA_SLOTSTATE_LINKINIT: case DVB_CA_SLOTSTATE_LINKINIT:
flags = ca->pub->read_cam_control(pubca, slot, CTRLIF_STATUS); flags = ca->pub->read_cam_control(pubca, slot, CTRLIF_STATUS);
if (flags & STATUSREG_DA) { if (flags & STATUSREG_DA) {
dprintk("CAM supports DA IRQ\n"); dprintk("CAM supports DA IRQ\n");
ca->slot_info[slot].da_irq_supported = 1; sl->da_irq_supported = 1;
} }
break; break;
...@@ -1059,7 +1065,9 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca) ...@@ -1059,7 +1065,9 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca)
* call might take several hundred milliseconds until timeout! * call might take several hundred milliseconds until timeout!
*/ */
for (slot = 0; slot < ca->slot_count; slot++) { for (slot = 0; slot < ca->slot_count; slot++) {
switch (ca->slot_info[slot].slot_state) { struct dvb_ca_slot *sl = &ca->slot_info[slot];
switch (sl->slot_state) {
default: default:
case DVB_CA_SLOTSTATE_NONE: case DVB_CA_SLOTSTATE_NONE:
delay = HZ * 60; /* 60s */ delay = HZ * 60; /* 60s */
...@@ -1085,7 +1093,7 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca) ...@@ -1085,7 +1093,7 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca)
if (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) if (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE))
delay = HZ / 10; /* 100ms */ delay = HZ / 10; /* 100ms */
if (ca->open) { if (ca->open) {
if ((!ca->slot_info[slot].da_irq_supported) || if ((!sl->da_irq_supported) ||
(!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_DA))) (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_DA)))
delay = HZ / 10; /* 100ms */ delay = HZ / 10; /* 100ms */
} }
...@@ -1374,15 +1382,17 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file, ...@@ -1374,15 +1382,17 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
switch (cmd) { switch (cmd) {
case CA_RESET: case CA_RESET:
for (slot = 0; slot < ca->slot_count; slot++) { for (slot = 0; slot < ca->slot_count; slot++) {
mutex_lock(&ca->slot_info[slot].slot_lock); struct dvb_ca_slot *sl = &ca->slot_info[slot];
if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE) {
mutex_lock(&sl->slot_lock);
if (sl->slot_state != DVB_CA_SLOTSTATE_NONE) {
dvb_ca_en50221_slot_shutdown(ca, slot); dvb_ca_en50221_slot_shutdown(ca, slot);
if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)
dvb_ca_en50221_camchange_irq(ca->pub, dvb_ca_en50221_camchange_irq(ca->pub,
slot, slot,
DVB_CA_EN50221_CAMCHANGE_INSERTED); DVB_CA_EN50221_CAMCHANGE_INSERTED);
} }
mutex_unlock(&ca->slot_info[slot].slot_lock); mutex_unlock(&sl->slot_lock);
} }
ca->next_read_slot = 0; ca->next_read_slot = 0;
dvb_ca_en50221_thread_wakeup(ca); dvb_ca_en50221_thread_wakeup(ca);
...@@ -1400,21 +1410,23 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file, ...@@ -1400,21 +1410,23 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
case CA_GET_SLOT_INFO: { case CA_GET_SLOT_INFO: {
struct ca_slot_info *info = parg; struct ca_slot_info *info = parg;
struct dvb_ca_slot *sl;
if ((info->num > ca->slot_count) || (info->num < 0)) { slot = info->num;
if ((slot > ca->slot_count) || (slot < 0)) {
err = -EINVAL; err = -EINVAL;
goto out_unlock; goto out_unlock;
} }
info->type = CA_CI_LINK; info->type = CA_CI_LINK;
info->flags = 0; info->flags = 0;
if ((ca->slot_info[info->num].slot_state != DVB_CA_SLOTSTATE_NONE) sl = &ca->slot_info[slot];
&& (ca->slot_info[info->num].slot_state != DVB_CA_SLOTSTATE_INVALID)) { if ((sl->slot_state != DVB_CA_SLOTSTATE_NONE) &&
(sl->slot_state != DVB_CA_SLOTSTATE_INVALID)) {
info->flags = CA_CI_MODULE_PRESENT; info->flags = CA_CI_MODULE_PRESENT;
} }
if (ca->slot_info[info->num].slot_state == DVB_CA_SLOTSTATE_RUNNING) { if (sl->slot_state == DVB_CA_SLOTSTATE_RUNNING)
info->flags |= CA_CI_MODULE_READY; info->flags |= CA_CI_MODULE_READY;
}
break; break;
} }
...@@ -1462,6 +1474,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file, ...@@ -1462,6 +1474,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
struct dvb_ca_private *ca = dvbdev->priv; struct dvb_ca_private *ca = dvbdev->priv;
struct dvb_ca_slot *sl;
u8 slot, connection_id; u8 slot, connection_id;
int status; int status;
u8 fragbuf[HOST_LINK_BUF_SIZE]; u8 fragbuf[HOST_LINK_BUF_SIZE];
...@@ -1483,14 +1496,15 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file, ...@@ -1483,14 +1496,15 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
return -EFAULT; return -EFAULT;
buf += 2; buf += 2;
count -= 2; count -= 2;
sl = &ca->slot_info[slot];
/* check if the slot is actually running */ /* check if the slot is actually running */
if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) if (sl->slot_state != DVB_CA_SLOTSTATE_RUNNING)
return -EINVAL; return -EINVAL;
/* fragment the packets & store in the buffer */ /* fragment the packets & store in the buffer */
while (fragpos < count) { while (fragpos < count) {
fraglen = ca->slot_info[slot].link_buf_size - 2; fraglen = sl->link_buf_size - 2;
if (fraglen < 0) if (fraglen < 0)
break; break;
if (fraglen > HOST_LINK_BUF_SIZE - 2) if (fraglen > HOST_LINK_BUF_SIZE - 2)
...@@ -1510,14 +1524,14 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file, ...@@ -1510,14 +1524,14 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
written = 0; written = 0;
while (!time_after(jiffies, timeout)) { while (!time_after(jiffies, timeout)) {
/* check the CAM hasn't been removed/reset in the meantime */ /* check the CAM hasn't been removed/reset in the meantime */
if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) { if (sl->slot_state != DVB_CA_SLOTSTATE_RUNNING) {
status = -EIO; status = -EIO;
goto exit; goto exit;
} }
mutex_lock(&ca->slot_info[slot].slot_lock); mutex_lock(&sl->slot_lock);
status = dvb_ca_en50221_write_data(ca, slot, fragbuf, fraglen + 2); status = dvb_ca_en50221_write_data(ca, slot, fragbuf, fraglen + 2);
mutex_unlock(&ca->slot_info[slot].slot_lock); mutex_unlock(&sl->slot_lock);
if (status == (fraglen + 2)) { if (status == (fraglen + 2)) {
written = 1; written = 1;
break; break;
...@@ -1557,16 +1571,17 @@ static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private *ca, ...@@ -1557,16 +1571,17 @@ static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private *ca,
slot = ca->next_read_slot; slot = ca->next_read_slot;
while ((slot_count < ca->slot_count) && (!found)) { while ((slot_count < ca->slot_count) && (!found)) {
if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) struct dvb_ca_slot *sl = &ca->slot_info[slot];
if (sl->slot_state != DVB_CA_SLOTSTATE_RUNNING)
goto nextslot; goto nextslot;
if (ca->slot_info[slot].rx_buffer.data == NULL) { if (!sl->rx_buffer.data)
return 0; return 0;
}
idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, -1, &fraglen); idx = dvb_ringbuffer_pkt_next(&sl->rx_buffer, -1, &fraglen);
while (idx != -1) { while (idx != -1) {
dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2); dvb_ringbuffer_pkt_read(&sl->rx_buffer, idx, 0, hdr, 2);
if (connection_id == -1) if (connection_id == -1)
connection_id = hdr[0]; connection_id = hdr[0];
if ((hdr[0] == connection_id) && ((hdr[1] & 0x80) == 0)) { if ((hdr[0] == connection_id) && ((hdr[1] & 0x80) == 0)) {
...@@ -1575,7 +1590,8 @@ static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private *ca, ...@@ -1575,7 +1590,8 @@ static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private *ca,
break; break;
} }
idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, idx, &fraglen); idx = dvb_ringbuffer_pkt_next(&sl->rx_buffer, idx,
&fraglen);
} }
nextslot: nextslot:
...@@ -1603,6 +1619,7 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, ...@@ -1603,6 +1619,7 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf,
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
struct dvb_ca_private *ca = dvbdev->priv; struct dvb_ca_private *ca = dvbdev->priv;
struct dvb_ca_slot *sl;
int status; int status;
int result = 0; int result = 0;
u8 hdr[2]; u8 hdr[2];
...@@ -1639,7 +1656,8 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, ...@@ -1639,7 +1656,8 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf,
return status; return status;
} }
idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, -1, &fraglen); sl = &ca->slot_info[slot];
idx = dvb_ringbuffer_pkt_next(&sl->rx_buffer, -1, &fraglen);
pktlen = 2; pktlen = 2;
do { do {
if (idx == -1) { if (idx == -1) {
...@@ -1649,7 +1667,7 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, ...@@ -1649,7 +1667,7 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf,
goto exit; goto exit;
} }
dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2); dvb_ringbuffer_pkt_read(&sl->rx_buffer, idx, 0, hdr, 2);
if (connection_id == -1) if (connection_id == -1)
connection_id = hdr[0]; connection_id = hdr[0];
if (hdr[0] == connection_id) { if (hdr[0] == connection_id) {
...@@ -1660,10 +1678,14 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, ...@@ -1660,10 +1678,14 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf,
fraglen -= 2; fraglen -= 2;
} }
if ((status = dvb_ringbuffer_pkt_read_user(&ca->slot_info[slot].rx_buffer, idx, 2, status =
buf + pktlen, fraglen)) < 0) { dvb_ringbuffer_pkt_read_user(&sl->rx_buffer,
idx, 2,
buf + pktlen,
fraglen);
if (status < 0)
goto exit; goto exit;
}
pktlen += fraglen; pktlen += fraglen;
} }
...@@ -1672,9 +1694,9 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, ...@@ -1672,9 +1694,9 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf,
dispose = 1; dispose = 1;
} }
idx2 = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, idx, &fraglen); idx2 = dvb_ringbuffer_pkt_next(&sl->rx_buffer, idx, &fraglen);
if (dispose) if (dispose)
dvb_ringbuffer_pkt_dispose(&ca->slot_info[slot].rx_buffer, idx); dvb_ringbuffer_pkt_dispose(&sl->rx_buffer, idx);
idx = idx2; idx = idx2;
dispose = 0; dispose = 0;
} while (!last_fragment); } while (!last_fragment);
...@@ -1720,15 +1742,16 @@ static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file) ...@@ -1720,15 +1742,16 @@ static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file)
} }
for (i = 0; i < ca->slot_count; i++) { for (i = 0; i < ca->slot_count; i++) {
struct dvb_ca_slot *sl = &ca->slot_info[i];
if (ca->slot_info[i].slot_state == DVB_CA_SLOTSTATE_RUNNING) { if (sl->slot_state == DVB_CA_SLOTSTATE_RUNNING) {
if (ca->slot_info[i].rx_buffer.data != NULL) { if (!sl->rx_buffer.data) {
/* /*
* it is safe to call this here without locks * it is safe to call this here without locks
* because ca->open == 0. Data is not read in * because ca->open == 0. Data is not read in
* this case * this case
*/ */
dvb_ringbuffer_flush(&ca->slot_info[i].rx_buffer); dvb_ringbuffer_flush(&sl->rx_buffer);
} }
} }
} }
...@@ -1888,11 +1911,13 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, ...@@ -1888,11 +1911,13 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
/* now initialise each slot */ /* now initialise each slot */
for (i = 0; i < slot_count; i++) { for (i = 0; i < slot_count; i++) {
memset(&ca->slot_info[i], 0, sizeof(struct dvb_ca_slot)); struct dvb_ca_slot *sl = &ca->slot_info[i];
ca->slot_info[i].slot_state = DVB_CA_SLOTSTATE_NONE;
atomic_set(&ca->slot_info[i].camchange_count, 0); memset(sl, 0, sizeof(struct dvb_ca_slot));
ca->slot_info[i].camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED; sl->slot_state = DVB_CA_SLOTSTATE_NONE;
mutex_init(&ca->slot_info[i].slot_lock); atomic_set(&sl->camchange_count, 0);
sl->camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED;
mutex_init(&sl->slot_lock);
} }
mutex_init(&ca->ioctl_mutex); mutex_init(&ca->ioctl_mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册