linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Chhao Chang (常浩)" <ot_chhao.chang@mediatek.com>
To: "dan.carpenter@linaro.org" <dan.carpenter@linaro.org>
Cc: "linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [bug report] pinctrl: mediatek: Add EINT support for multiple addresses
Date: Wed, 26 Mar 2025 03:11:05 +0000	[thread overview]
Message-ID: <5ae93d42e4c4e70fb33bf35dcc37caebf324c8d3.camel@mediatek.com> (raw)
In-Reply-To: <dac846e5-d15d-4def-a7e3-ce17e74e2da6@stanley.mountain>

On Tue, 2025-03-25 at 08:45 +0300, Dan Carpenter wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> Hello Hao Chang,
> 
> Commit 3ef9f710efcb ("pinctrl: mediatek: Add EINT support for
> multiple addresses") from Mar 22, 2025 (linux-next), leads to the
> following Smatch static checker warning:
> 
>         drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c:384
> mtk_build_eint()
>         warn: error code type promoted to positive: 'count_reg_names'
> 
> drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
>     374                 return 0;
>     375
>     376         if (!of_property_read_bool(np, "interrupt-
> controller"))
>     377                 return -ENODEV;
>     378
>     379         hw->eint = devm_kzalloc(hw->dev, sizeof(*hw->eint),
> GFP_KERNEL);
>     380         if (!hw->eint)
>     381                 return -ENOMEM;
>     382
>     383         count_reg_names = of_property_count_strings(np, "reg-
> names");
> --> 384         if (count_reg_names < hw->soc->nbase_names)
> 
> count_reg_names is type int but hw->soc->nbase_names is unsigned
> int.  So
> if of_property_count_strings() returns a negative error code then
> it's
> type promoted as a high positive unsigned int value and treated as
> success.
> 
>     385                 return -EINVAL;
>     386
>     387         hw->eint->nbase = count_reg_names - hw->soc-
> >nbase_names;
> 
> hw->eint->nbase is a u8 so the negative value is truncated to a low
> positive
> value.
> 
>     388         hw->eint->base = devm_kmalloc_array(&pdev->dev, hw-
> >eint->nbase,
>     389                                             sizeof(*hw->eint-
> >base), GFP_KERNEL | __GFP_ZERO);
> 
> This allocation will always succeed.
Thanks for your suggestion, I will fix this.
> 
> regards,
> dan carpenter
> 
>     390         if (!hw->eint->base) {
>     391                 ret = -ENOMEM;
>     392                 goto err_free_base;
>     393         }
>     394
>     395         for (i = hw->soc->nbase_names, j = 0; i <
> count_reg_names; i++, j++) {
>     396                 hw->eint->base[j] = of_iomap(np, i);
>     397                 if (IS_ERR(hw->eint->base[j])) {
>     398                         ret = PTR_ERR(hw->eint->base[j]);
>     399                         goto err_free_eint;
>     400                 }
>     401         }
>     402
> 

      parent reply	other threads:[~2025-03-26  3:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25  5:45 [bug report] pinctrl: mediatek: Add EINT support for multiple addresses Dan Carpenter
2025-03-25  5:47 ` Dan Carpenter
2025-03-26  3:11 ` Chhao Chang (常浩) [this message]

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=5ae93d42e4c4e70fb33bf35dcc37caebf324c8d3.camel@mediatek.com \
    --to=ot_chhao.chang@mediatek.com \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).