public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Cc: Bartosz Golaszewski <brgl@bgdev.pl>, Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH v1 3/7] gpio: 74x164: Annotate buffer with __counted_by()
Date: Tue, 4 Feb 2025 11:58:02 +1030	[thread overview]
Message-ID: <82b97884-19a3-4948-8212-d0fd38669ee2@embeddedor.com> (raw)
In-Reply-To: <20250203121843.3183991-4-andriy.shevchenko@linux.intel.com>



On 03/02/25 22:47, Andy Shevchenko wrote:
> Add the __counted_by() compiler attribute to the flexible array member
> volumes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
> 
> Use struct_size() instead of manually calculating the number of bytes to
> allocate the private structure with a buffer.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>   drivers/gpio/gpio-74x164.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c
> index 70c662bbca7b..7844f8a58834 100644
> --- a/drivers/gpio/gpio-74x164.c
> +++ b/drivers/gpio/gpio-74x164.c
> @@ -30,7 +30,7 @@ struct gen_74x164_chip {
>   	 * register at the end of the transfer. So, to have a logical
>   	 * numbering, store the bytes in reverse order.
>   	 */
> -	u8			buffer[];
> +	u8			buffer[] __counted_by(registers);
>   };
>   
>   static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
> @@ -97,6 +97,7 @@ static int gen_74x164_direction_output(struct gpio_chip *gc,
>   
>   static int gen_74x164_probe(struct spi_device *spi)
>   {
> +	struct device *dev = &spi->dev;
>   	struct gen_74x164_chip *chip;
>   	u32 nregs;
>   	int ret;
> @@ -116,10 +117,12 @@ static int gen_74x164_probe(struct spi_device *spi)
>   		return -EINVAL;
>   	}
>   
> -	chip = devm_kzalloc(&spi->dev, sizeof(*chip) + nregs, GFP_KERNEL);
> +	chip = devm_kzalloc(dev, struct_size(chip, buffer, nregs), GFP_KERNEL);
>   	if (!chip)
>   		return -ENOMEM;
>   
> +	chip->registers = nregs;
> +
>   	chip->gpiod_oe = devm_gpiod_get_optional(&spi->dev, "enable",
>   						 GPIOD_OUT_LOW);
>   	if (IS_ERR(chip->gpiod_oe))
> @@ -133,10 +136,7 @@ static int gen_74x164_probe(struct spi_device *spi)
>   	chip->gpio_chip.set = gen_74x164_set_value;
>   	chip->gpio_chip.set_multiple = gen_74x164_set_multiple;
>   	chip->gpio_chip.base = -1;
> -
> -	chip->registers = nregs;
>   	chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers;
> -
>   	chip->gpio_chip.can_sleep = true;
>   	chip->gpio_chip.parent = &spi->dev;
>   	chip->gpio_chip.owner = THIS_MODULE;


  reply	other threads:[~2025-02-04  1:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03 12:17 [PATCH v1 0/7] gpio: 74x164: Refactor and clean up the driver Andy Shevchenko
2025-02-03 12:17 ` [PATCH v1 1/7] gpio: 74x164: Remove unneeded dependency to OF_GPIO Andy Shevchenko
2025-02-07  8:01   ` Bartosz Golaszewski
2025-02-07  8:56     ` Geert Uytterhoeven
2025-02-03 12:17 ` [PATCH v1 2/7] gpio: 74x164: Simplify code with cleanup helpers Andy Shevchenko
2025-02-10  9:12   ` Linus Walleij
2025-02-03 12:17 ` [PATCH v1 3/7] gpio: 74x164: Annotate buffer with __counted_by() Andy Shevchenko
2025-02-04  1:28   ` Gustavo A. R. Silva [this message]
2025-02-03 12:17 ` [PATCH v1 4/7] gpio: 74x164: Make use of the macros from bits.h Andy Shevchenko
2025-02-10  9:12   ` Linus Walleij
2025-02-10  9:16     ` Andy Shevchenko
2025-02-03 12:17 ` [PATCH v1 5/7] gpio: 74x164: Fully convert to use managed resources Andy Shevchenko
2025-02-07  8:22   ` Bartosz Golaszewski
2025-02-03 12:17 ` [PATCH v1 6/7] gpio: 74x164: Switch to use dev_err_probe() Andy Shevchenko
2025-02-11  9:15   ` Linus Walleij
2025-02-03 12:17 ` [PATCH v1 7/7] gpio: 74x164: Utilise temporary variable for struct device Andy Shevchenko

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=82b97884-19a3-4948-8212-d0fd38669ee2@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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