media: dvb_ca_en50221: fix a size write bug
[ Upstream commit a4315e5be7
]
The function of "dvb_ca_en50221_write_data" at source/drivers/media
/dvb-core/dvb_ca_en50221.c is used for two cases.
The first case is for writing APDU data in the function of
"dvb_ca_en50221_io_write" at source/drivers/media/dvb-core/
dvb_ca_en50221.c.
The second case is for writing the host link buf size on the
Command Register in the function of "dvb_ca_en50221_link_init"
at source/drivers/media/dvb-core/dvb_ca_en50221.c.
In the second case, there exists a bug like following.
In the function of the "dvb_ca_en50221_link_init",
after a TV host calculates the host link buf_size,
the TV host writes the calculated host link buf_size on the
Size Register.
Accroding to the en50221 Spec (the page 60 of
https://dvb.org/wp-content/uploads/2020/02/En50221.V1.pdf),
before this writing operation, the "SW(CMDREG_SW)" flag in the
Command Register should be set. We can see this setting operation
in the function of the "dvb_ca_en50221_link_init" like below.
...
if ((ret = ca->pub->write_cam_control(ca->pub, slot,
CTRLIF_COMMAND, IRQEN | CMDREG_SW)) != 0)
return ret;
...
But, after that, the real writing operation is implemented using
the function of the "dvb_ca_en50221_write_data" in the function of
"dvb_ca_en50221_link_init", and the "dvb_ca_en50221_write_data"
includes the function of "ca->pub->write_cam_control",
and the function of the "ca->pub->write_cam_control" in the
function of the "dvb_ca_en50221_wrte_data" does not include
"CMDREG_SW" flag like below.
...
if ((status = ca->pub->write_cam_control(ca->pub, slot,
CTRLIF_COMMAND, IRQEN | CMDREG_HC)) != 0)
...
In the above source code, we can see only the "IRQEN | CMDREG_HC",
but we cannot see the "CMDREG_SW".
The "CMDREG_SW" flag which was set in the function of the
"dvb_ca_en50221_link_init" was rollbacked by the follwoing function
of the "dvb_ca_en50221_write_data".
This is a bug. and this bug causes that the calculated host link buf_size
is not properly written in the CI module.
Through this patch, we fix this bug.
Link: https://lore.kernel.org/linux-media/20220818125027.1131-1-yongsuyoo0215@gmail.com
Signed-off-by: YongSu Yoo <yongsuyoo0215@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
b66849f354
commit
46e8b0fe53
@ -187,7 +187,7 @@ static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca);
|
|||||||
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);
|
||||||
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 *ebuf, int ecount);
|
u8 *ebuf, int ecount, int size_write_flag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safely find needle in haystack.
|
* Safely find needle in haystack.
|
||||||
@ -370,7 +370,7 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot)
|
|||||||
ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_FR, HZ / 10);
|
ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_FR, HZ / 10);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
ret = dvb_ca_en50221_write_data(ca, slot, buf, 2);
|
ret = dvb_ca_en50221_write_data(ca, slot, buf, 2, CMDREG_SW);
|
||||||
if (ret != 2)
|
if (ret != 2)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN);
|
ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN);
|
||||||
@ -778,11 +778,13 @@ exit:
|
|||||||
* @buf: The data in this buffer is treated as a complete link-level packet to
|
* @buf: The data in this buffer is treated as a complete link-level packet to
|
||||||
* be written.
|
* be written.
|
||||||
* @bytes_write: Size of ebuf.
|
* @bytes_write: Size of ebuf.
|
||||||
|
* @size_write_flag: A flag on Command Register which says whether the link size
|
||||||
|
* information will be writen or not.
|
||||||
*
|
*
|
||||||
* return: Number of bytes written, or < 0 on error.
|
* return: Number of bytes written, or < 0 on error.
|
||||||
*/
|
*/
|
||||||
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, int size_write_flag)
|
||||||
{
|
{
|
||||||
struct dvb_ca_slot *sl = &ca->slot_info[slot];
|
struct dvb_ca_slot *sl = &ca->slot_info[slot];
|
||||||
int status;
|
int status;
|
||||||
@ -817,7 +819,7 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
|
|||||||
|
|
||||||
/* OK, set HC bit */
|
/* OK, set HC bit */
|
||||||
status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND,
|
status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND,
|
||||||
IRQEN | CMDREG_HC);
|
IRQEN | CMDREG_HC | size_write_flag);
|
||||||
if (status)
|
if (status)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
@ -1505,7 +1507,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
|
|||||||
|
|
||||||
mutex_lock(&sl->slot_lock);
|
mutex_lock(&sl->slot_lock);
|
||||||
status = dvb_ca_en50221_write_data(ca, slot, fragbuf,
|
status = dvb_ca_en50221_write_data(ca, slot, fragbuf,
|
||||||
fraglen + 2);
|
fraglen + 2, 0);
|
||||||
mutex_unlock(&sl->slot_lock);
|
mutex_unlock(&sl->slot_lock);
|
||||||
if (status == (fraglen + 2)) {
|
if (status == (fraglen + 2)) {
|
||||||
written = 1;
|
written = 1;
|
||||||
|
Reference in New Issue
Block a user