Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: alsa-devel@alsa-project.org
Subject: Re: [bug report] soundwire: qcom: Check device status before reading devid
Date: Fri, 8 Jul 2022 11:45:56 +0300	[thread overview]
Message-ID: <20220708084555.GJ2316@kadam> (raw)
In-Reply-To: <747099de-504a-daed-6d45-34bf0e379562@linaro.org>

On Fri, Jul 08, 2022 at 09:31:31AM +0100, Srinivas Kandagatla wrote:
> Hi Dan,
> 
> On 08/07/2022 09:08, Dan Carpenter wrote:
> > Hello Srinivas Kandagatla,
> > 
> > The patch aa1262ca6695: "soundwire: qcom: Check device status before
> > reading devid" from Jul 6, 2022, leads to the following Smatch static
> > checker warning:
> > 
> > 	drivers/soundwire/qcom.c:484 qcom_swrm_enumerate()
> > 	error: buffer overflow 'ctrl->status' 11 <= 11
> > 
> > drivers/soundwire/qcom.c
> >      471 static int qcom_swrm_enumerate(struct sdw_bus *bus)
> >      472 {
> >      473         struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus);
> >      474         struct sdw_slave *slave, *_s;
> >      475         struct sdw_slave_id id;
> >      476         u32 val1, val2;
> >      477         bool found;
> >      478         u64 addr;
> >      479         int i;
> >      480         char *buf1 = (char *)&val1, *buf2 = (char *)&val2;
> >      481
> >      482         for (i = 1; i <= SDW_MAX_DEVICES; i++) {
> >                       ^^^^^
> > This a loop that starts from 1 instead of 0.  I looked at the
> > surrounding context and it seems like it should be a normal loop that
> > starts at 0 and goes to < SDW_MAX_DEVICES.
> > 
> 
> In SoundWire world device id 0 is special one and used for enumerating the
> SoundWire devices.
> 
> Only addresses from 1-11 are valid devids that can be assigned to devices by
> the host/controller.
> 
> This part of the code is reading the devids assigned by the hw
> auto-enumeration, So the loop start from 1 is correct here.
> 
> 
> > (Or possibly the other loops are buggy as well).
> 
> Atleast this code is fine, but I see other places where are starting from 0
> which could be fixed but the SoundWire core will ignore the status for devid
> 0.

This code is *not* fine either because it should be < instead of <=.

It might be that we always hit a zero first and break so the bug might
not affect users but it's still wrong.

regards,
dan carpenter


  reply	other threads:[~2022-07-08  8:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08  8:08 [bug report] soundwire: qcom: Check device status before reading devid Dan Carpenter
2022-07-08  8:31 ` Srinivas Kandagatla
2022-07-08  8:45   ` Dan Carpenter [this message]
2022-07-08  9:02     ` Srinivas Kandagatla
2022-07-08 14:04       ` Pierre-Louis Bossart

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=20220708084555.GJ2316@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=srinivas.kandagatla@linaro.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox