[alsa-devel] [PATCH 1/2] soundwire: Fix a signedness bug
"ret" is an int and "buf" is a u8. sdw_read() returns negative error codes which are truncated to the u8, 0-255 range before being stored as an int. It means that "ret" can't be less than zero.
Fixes: b0a9c37b0178 ("soundwire: Add slave status handling") Signed-off-by: Dan Carpenter dan.carpenter@oracle.com
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 4c345197eb55..ac88031f7664 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -771,12 +771,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) sdw_modify_slave_status(slave, SDW_SLAVE_ALERT);
/* Read Instat 1, Instat 2 and Instat 3 registers */ - ret = buf = sdw_read(slave, SDW_SCP_INT1); + ret = sdw_read(slave, SDW_SCP_INT1); if (ret < 0) { dev_err(slave->bus->dev, "SDW_SCP_INT1 read failed:%d", ret); return ret; } + buf = ret;
ret = sdw_nread(slave, SDW_SCP_INTSTAT2, 2, buf2); if (ret < 0) { @@ -870,12 +871,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) * Read status again to ensure no new interrupts arrived * while servicing interrupts. */ - ret = _buf = sdw_read(slave, SDW_SCP_INT1); + ret = sdw_read(slave, SDW_SCP_INT1); if (ret < 0) { dev_err(slave->bus->dev, "SDW_SCP_INT1 read failed:%d", ret); return ret; } + _buf = ret;
ret = sdw_nread(slave, SDW_SCP_INTSTAT2, 2, _buf2); if (ret < 0) {
We should be using "status2" here instead of "status".
Fixes: b0a9c37b0178 ("soundwire: Add slave status handling") Signed-off-by: Dan Carpenter dan.carpenter@oracle.com
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index ac88031f7664..a5d41a4a1609 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -741,10 +741,10 @@ static int sdw_handle_port_interrupt(struct sdw_slave *slave,
/* Read DPN interrupt again */ status2 = sdw_read(slave, addr); - if (status < 0) { + if (status2 < 0) { dev_err(slave->bus->dev, - "SDW_DPN_INT read failed:%d", status); - return status; + "SDW_DPN_INT read failed:%d", status2); + return status2; } status &= status2;
On Tue, Jan 09, 2018 at 12:37:44PM +0300, Dan Carpenter wrote:
We should be using "status2" here instead of "status".
This is already fixed by commit:
Author: Wei Yongjun weiyongjun1@huawei.com Date: Mon Jan 8 22:22:44 2018 +0530
soundwire: Fix typo in return value check of sdw_read()
Fix the typo, 'status' should be instead of 'status2'.
Fixes: b0a9c37b0178 ("soundwire: Add slave status handling") Signed-off-by: Dan Carpenter dan.carpenter@oracle.com
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index ac88031f7664..a5d41a4a1609 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -741,10 +741,10 @@ static int sdw_handle_port_interrupt(struct sdw_slave *slave,
/* Read DPN interrupt again */ status2 = sdw_read(slave, addr);
if (status < 0) {
if (status2 < 0) { dev_err(slave->bus->dev,
"SDW_DPN_INT read failed:%d", status);
return status;
"SDW_DPN_INT read failed:%d", status2);
} status &= status2;return status2;
On Wed, Jan 10, 2018 at 04:25:44PM +0530, Vinod Koul wrote:
On Tue, Jan 09, 2018 at 12:37:44PM +0300, Dan Carpenter wrote:
We should be using "status2" here instead of "status".
This is already fixed by commit:
Author: Wei Yongjun weiyongjun1@huawei.com Date: Mon Jan 8 22:22:44 2018 +0530
soundwire: Fix typo in return value check of sdw_read() Fix the typo, 'status' should be instead of 'status2'.
Hi Wei,
It looks like you're fixing static checker warnings? Could you CC kernel-janitors@vger.kernel.org for those fixes? Otherwise we end up sending duplicates a lot.
Colin King, Julia Lawall, Christophe JAILLET, and I all CC our static checker fixes to kernel-janitors. I still end up sending duplicates sometimes... Which is fine.
regards, dan carpenter
Hi Dan Carpenter
Hi Wei,
It looks like you're fixing static checker warnings? Could you CC kernel-janitors@vger.kernel.org for those fixes? Otherwise we end up sending duplicates a lot.
Colin King, Julia Lawall, Christophe JAILLET, and I all CC our static checker fixes to kernel-janitors. I still end up sending duplicates sometimes... Which is fine.
Yes, I am running a static checker. I will CC kernel-janitors@vger.kernel.org for those later patches.
Regards, Yongjun Wei
On Tue, Jan 09, 2018 at 12:37:00PM +0300, Dan Carpenter wrote:
"ret" is an int and "buf" is a u8. sdw_read() returns negative error codes which are truncated to the u8, 0-255 range before being stored as an int. It means that "ret" can't be less than zero.
Fixes: b0a9c37b0178 ("soundwire: Add slave status handling") Signed-off-by: Dan Carpenter dan.carpenter@oracle.com
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 4c345197eb55..ac88031f7664 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -771,12 +771,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) sdw_modify_slave_status(slave, SDW_SLAVE_ALERT);
/* Read Instat 1, Instat 2 and Instat 3 registers */
- ret = buf = sdw_read(slave, SDW_SCP_INT1);
- ret = sdw_read(slave, SDW_SCP_INT1);
How about:
buf = ret = sdw_read(slave, SDW_SCP_INT1);
That should make sure truncation happens latter, but then this is simpler to read...
if (ret < 0) { dev_err(slave->bus->dev, "SDW_SCP_INT1 read failed:%d", ret); return ret; }
buf = ret;
ret = sdw_nread(slave, SDW_SCP_INTSTAT2, 2, buf2); if (ret < 0) {
@@ -870,12 +871,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) * Read status again to ensure no new interrupts arrived * while servicing interrupts. */
ret = _buf = sdw_read(slave, SDW_SCP_INT1);
ret = sdw_read(slave, SDW_SCP_INT1);
if (ret < 0) { dev_err(slave->bus->dev, "SDW_SCP_INT1 read failed:%d", ret); return ret; }
_buf = ret;
ret = sdw_nread(slave, SDW_SCP_INTSTAT2, 2, _buf2); if (ret < 0) {
Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
"ret" is an int and "buf" is a u8. sdw_read() returns negative error codes which are truncated to the u8, 0-255 range before being stored as an int. It means that "ret" can't be less than zero.
Fixes: b0a9c37b0178 ("soundwire: Add slave status handling") Signed-off-by: Dan Carpenter dan.carpenter@oracle.com --- v2: style change
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 4c345197eb55..ae698e63bdf6 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -771,7 +771,7 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) sdw_modify_slave_status(slave, SDW_SLAVE_ALERT);
/* Read Instat 1, Instat 2 and Instat 3 registers */ - ret = buf = sdw_read(slave, SDW_SCP_INT1); + buf = ret = sdw_read(slave, SDW_SCP_INT1); if (ret < 0) { dev_err(slave->bus->dev, "SDW_SCP_INT1 read failed:%d", ret); @@ -870,7 +870,7 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) * Read status again to ensure no new interrupts arrived * while servicing interrupts. */ - ret = _buf = sdw_read(slave, SDW_SCP_INT1); + _buf = ret = sdw_read(slave, SDW_SCP_INT1); if (ret < 0) { dev_err(slave->bus->dev, "SDW_SCP_INT1 read failed:%d", ret);
participants (3)
-
Dan Carpenter
-
Vinod Koul
-
weiyongjun (A)