From: Vinod Koul <vinod.koul@intel.com> To: Dan Carpenter <dan.carpenter@oracle.com> Cc: Sanyog Kale <sanyog.r.kale@intel.com>, kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH 1/2] soundwire: Fix a signedness bug Date: Wed, 10 Jan 2018 10:50:16 +0000 [thread overview] Message-ID: <20180110105425.GY18649@localhost> (raw) In-Reply-To: <20180109093700.7275ardpus7g6rkq@mwanda> 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 -- ~Vinod
WARNING: multiple messages have this Message-ID (diff)
From: Vinod Koul <vinod.koul@intel.com> To: Dan Carpenter <dan.carpenter@oracle.com> Cc: Sanyog Kale <sanyog.r.kale@intel.com>, kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH 1/2] soundwire: Fix a signedness bug Date: Wed, 10 Jan 2018 16:24:25 +0530 [thread overview] Message-ID: <20180110105425.GY18649@localhost> (raw) In-Reply-To: <20180109093700.7275ardpus7g6rkq@mwanda> 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 -- ~Vinod
next prev parent reply other threads:[~2018-01-10 10:50 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-01-09 9:37 [PATCH 1/2] soundwire: Fix a signedness bug Dan Carpenter 2018-01-09 9:37 ` Dan Carpenter 2018-01-09 9:37 ` [PATCH 2/2] soundwire: Testing the wrong variable Dan Carpenter 2018-01-09 9:37 ` Dan Carpenter 2018-01-10 10:51 ` Vinod Koul 2018-01-10 10:55 ` Vinod Koul 2018-01-10 12:25 ` Dan Carpenter 2018-01-10 12:25 ` Dan Carpenter 2018-01-10 12:45 ` weiyongjun (A) 2018-01-10 10:50 ` Vinod Koul [this message] 2018-01-10 10:54 ` [alsa-devel] [PATCH 1/2] soundwire: Fix a signedness bug Vinod Koul 2018-01-10 12:29 ` [PATCH v2] " Dan Carpenter 2018-01-10 12:29 ` Dan Carpenter
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180110105425.GY18649@localhost \ --to=vinod.koul@intel.com \ --cc=alsa-devel@alsa-project.org \ --cc=dan.carpenter@oracle.com \ --cc=kernel-janitors@vger.kernel.org \ --cc=sanyog.r.kale@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.