All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang7@gmail.com>
To: Lee Jones <lee.jones@linaro.org>
Cc: Johan Hovold <johan@kernel.org>, Orson Zhai <orsonzhai@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	Chunyan Zhang <zhang.lyra@gmail.com>
Subject: Re: [PATCH 4/5] mfd: sprd-sc27xx-spi: Fix divide by zero when allocating register offset/mask
Date: Mon, 29 Jun 2020 22:35:06 +0800	[thread overview]
Message-ID: <CADBw62r_tkGEr9kHpojAi+fJ+qUqbsc-DQgG1TUAwOdbDXTgNQ@mail.gmail.com> (raw)
In-Reply-To: <20200629140137.GK177734@dell>

On Mon, Jun 29, 2020 at 10:01 PM Lee Jones <lee.jones@linaro.org> wrote:
>
> On Mon, 29 Jun 2020, Johan Hovold wrote:
>
> > On Mon, Jun 29, 2020 at 01:32:14PM +0100, Lee Jones wrote:
> > > Since ddata->irqs[] is already zeroed when allocated by devm_kcalloc() and
> > > dividing 0 by anything is still 0, there is no need to re-assign
> > > ddata->irqs[i].* values.  Instead, it should be safe to begin at 1.
> > >
> > > This fixes the following W=1 warning:
> > >
> > >  drivers/mfd/sprd-sc27xx-spi.c:255 sprd_pmic_probe() debug: sval_binop_unsigned: divide by zero
> > >
> > > Cc: Orson Zhai <orsonzhai@gmail.com>
> > > Cc: Baolin Wang <baolin.wang7@gmail.com>
> > > Cc: Chunyan Zhang <zhang.lyra@gmail.com>
> > > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> > > ---
> > >  drivers/mfd/sprd-sc27xx-spi.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mfd/sprd-sc27xx-spi.c b/drivers/mfd/sprd-sc27xx-spi.c
> > > index c305e941e435c..694a7d429ccff 100644
> > > --- a/drivers/mfd/sprd-sc27xx-spi.c
> > > +++ b/drivers/mfd/sprd-sc27xx-spi.c
> > > @@ -251,7 +251,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
> > >             return -ENOMEM;
> > >
> > >     ddata->irq_chip.irqs = ddata->irqs;
> > > -   for (i = 0; i < pdata->num_irqs; i++) {
> > > +   for (i = 1; i < pdata->num_irqs; i++) {
> > >             ddata->irqs[i].reg_offset = i / pdata->num_irqs;
> > >             ddata->irqs[i].mask = BIT(i % pdata->num_irqs);
> > >     }
> >
> > This doesn't look right either.
> >
> > First, the loop is never executed if num_irqs is zero.
>
> The point of the patch is that 0 entries are never processed.
>
> However, what I appear to have overlooked is that BIT(0 % x) is not 0,
> it's 1.

Yes.

>
> > Second, the current code looks bogus too as reg_offset is always set to
> > zero and mask to BIT(i)...

Now the result is correct, since all PMIC irq mask bits are in one
register now, which means the reg_offset is always 0 can work well.
But I think the logics still can be improved if our PMIC irq numbers
are larger than 32 in future.

>
> Heh.  I wonder if/how this was tested.
>
> I'm going to wait to hear from the authors before attempting to fix
> this again.
>
> Baolin, Could you please clarify this for us please?

Yes, see above comments.

-- 
Baolin Wang

WARNING: multiple messages have this Message-ID (diff)
From: Baolin Wang <baolin.wang7@gmail.com>
To: Lee Jones <lee.jones@linaro.org>
Cc: Orson Zhai <orsonzhai@gmail.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Johan Hovold <johan@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/5] mfd: sprd-sc27xx-spi: Fix divide by zero when allocating register offset/mask
Date: Mon, 29 Jun 2020 22:35:06 +0800	[thread overview]
Message-ID: <CADBw62r_tkGEr9kHpojAi+fJ+qUqbsc-DQgG1TUAwOdbDXTgNQ@mail.gmail.com> (raw)
In-Reply-To: <20200629140137.GK177734@dell>

On Mon, Jun 29, 2020 at 10:01 PM Lee Jones <lee.jones@linaro.org> wrote:
>
> On Mon, 29 Jun 2020, Johan Hovold wrote:
>
> > On Mon, Jun 29, 2020 at 01:32:14PM +0100, Lee Jones wrote:
> > > Since ddata->irqs[] is already zeroed when allocated by devm_kcalloc() and
> > > dividing 0 by anything is still 0, there is no need to re-assign
> > > ddata->irqs[i].* values.  Instead, it should be safe to begin at 1.
> > >
> > > This fixes the following W=1 warning:
> > >
> > >  drivers/mfd/sprd-sc27xx-spi.c:255 sprd_pmic_probe() debug: sval_binop_unsigned: divide by zero
> > >
> > > Cc: Orson Zhai <orsonzhai@gmail.com>
> > > Cc: Baolin Wang <baolin.wang7@gmail.com>
> > > Cc: Chunyan Zhang <zhang.lyra@gmail.com>
> > > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> > > ---
> > >  drivers/mfd/sprd-sc27xx-spi.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mfd/sprd-sc27xx-spi.c b/drivers/mfd/sprd-sc27xx-spi.c
> > > index c305e941e435c..694a7d429ccff 100644
> > > --- a/drivers/mfd/sprd-sc27xx-spi.c
> > > +++ b/drivers/mfd/sprd-sc27xx-spi.c
> > > @@ -251,7 +251,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
> > >             return -ENOMEM;
> > >
> > >     ddata->irq_chip.irqs = ddata->irqs;
> > > -   for (i = 0; i < pdata->num_irqs; i++) {
> > > +   for (i = 1; i < pdata->num_irqs; i++) {
> > >             ddata->irqs[i].reg_offset = i / pdata->num_irqs;
> > >             ddata->irqs[i].mask = BIT(i % pdata->num_irqs);
> > >     }
> >
> > This doesn't look right either.
> >
> > First, the loop is never executed if num_irqs is zero.
>
> The point of the patch is that 0 entries are never processed.
>
> However, what I appear to have overlooked is that BIT(0 % x) is not 0,
> it's 1.

Yes.

>
> > Second, the current code looks bogus too as reg_offset is always set to
> > zero and mask to BIT(i)...

Now the result is correct, since all PMIC irq mask bits are in one
register now, which means the reg_offset is always 0 can work well.
But I think the logics still can be improved if our PMIC irq numbers
are larger than 32 in future.

>
> Heh.  I wonder if/how this was tested.
>
> I'm going to wait to hear from the authors before attempting to fix
> this again.
>
> Baolin, Could you please clarify this for us please?

Yes, see above comments.

-- 
Baolin Wang

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-06-29 19:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29 12:32 [PATCH 0/5] Last batch of W=1 warning fixes in MFD Lee Jones
2020-06-29 12:32 ` Lee Jones
2020-06-29 12:32 ` [PATCH 1/5] mfd: si476x-cmd: Add missing documentation for si476x_cmd_fm_rds_status()'s arg 'report' Lee Jones
2020-06-29 12:32   ` Lee Jones
2020-06-29 12:32 ` [PATCH 2/5] mfd: lm3533-ctrlbank: Cap BRIGHTNESS_MAX to 127 since API uses u8 as carrier Lee Jones
2020-06-29 12:32   ` Lee Jones
2020-06-29 12:51   ` Johan Hovold
2020-06-29 12:51     ` Johan Hovold
2020-06-29 13:25     ` Lee Jones
2020-06-29 13:25       ` Lee Jones
2020-06-30  8:38       ` Johan Hovold
2020-06-30  8:38         ` Johan Hovold
2020-06-29 12:32 ` [PATCH 3/5] mfd: rave-sp: Fix mistake in 'struct rave_sp_deframer's kerneldoc Lee Jones
2020-06-29 12:32   ` Lee Jones
2020-06-29 12:32 ` [PATCH 4/5] mfd: sprd-sc27xx-spi: Fix divide by zero when allocating register offset/mask Lee Jones
2020-06-29 12:32   ` Lee Jones
2020-06-29 13:06   ` Johan Hovold
2020-06-29 13:06     ` Johan Hovold
2020-06-29 14:01     ` Lee Jones
2020-06-29 14:01       ` Lee Jones
2020-06-29 14:35       ` Baolin Wang [this message]
2020-06-29 14:35         ` Baolin Wang
2020-06-29 14:43         ` Johan Hovold
2020-06-29 14:43           ` Johan Hovold
2020-06-29 15:08           ` Baolin Wang
2020-06-29 15:08             ` Baolin Wang
2020-06-29 15:45             ` Lee Jones
2020-06-29 15:45               ` Lee Jones
2020-07-01  9:15   ` [PATCH] mfd: sprd-sc27xx-spi: Fix-up bogus IRQ register offset and mask setting Lee Jones
2020-07-01  9:15     ` Lee Jones
2020-07-01 14:10     ` Baolin Wang
2020-07-01 14:10       ` Baolin Wang
2020-06-29 12:32 ` [PATCH 5/5] mfd: axp20x-i2c: Do not define 'struct acpi_device_id' when !CONFIG_ACPI Lee Jones
2020-06-29 12:32   ` Lee Jones
2020-06-29 15:38   ` Chen-Yu Tsai
2020-06-29 15:38     ` Chen-Yu Tsai
2020-07-06  7:31     ` Lee Jones
2020-07-06  7:31       ` Lee Jones
2020-07-01  6:59   ` [PATCH v2] mfd: axp20x-i2c: Tell the compiler that ACPI functions may not be used Lee Jones
2020-07-01  6:59     ` Lee Jones
2020-07-01  8:38     ` Chen-Yu Tsai
2020-07-01  8:38       ` Chen-Yu Tsai

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=CADBw62r_tkGEr9kHpojAi+fJ+qUqbsc-DQgG1TUAwOdbDXTgNQ@mail.gmail.com \
    --to=baolin.wang7@gmail.com \
    --cc=johan@kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=zhang.lyra@gmail.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: link
Be 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.