linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array
@ 2023-07-12 17:19 Mark Brown
  2023-07-12 17:53 ` Jernej Škrabec
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mark Brown @ 2023-07-12 17:19 UTC (permalink / raw)
  To: Linus Walleij, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland
  Cc: linux-gpio, linux-arm-kernel, linux-sunxi, linux-kernel,
	Mark Brown

The sunxi pinctrl has a fixed size array it uses to store regulators used
in the driver. There is currently nothing that ensures that the number of
elements in the array is large enough to map the regulators defined by the
individual SoCs. While this is currently the case having an explicit check
in there will make life easier for anyone debugging memory issues that
manifest in the driver so let's add one.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 1dc1882cbdd7..1d1cd3d6d379 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -848,6 +848,9 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
 	char supply[16];
 	int ret;
 
+	if (WARN_ON_ONCE(bank_offset >= ARRAY_SIZE(pctl->regulators)))
+		return -EINVAL;
+
 	if (reg) {
 		refcount_inc(&s_reg->refcount);
 		return 0;

---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230711-pinctrl-sunxi-boudns-95bf5da3d075

Best regards,
-- 
Mark Brown <broonie@kernel.org>


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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array
  2023-07-12 17:19 [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array Mark Brown
@ 2023-07-12 17:53 ` Jernej Škrabec
  2023-07-12 17:57 ` Chen-Yu Tsai
  2023-07-20 19:33 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Jernej Škrabec @ 2023-07-12 17:53 UTC (permalink / raw)
  To: Linus Walleij, Chen-Yu Tsai, Samuel Holland, Mark Brown
  Cc: linux-gpio, linux-arm-kernel, linux-sunxi, linux-kernel,
	Mark Brown

Dne sreda, 12. julij 2023 ob 19:19:59 CEST je Mark Brown napisal(a):
> The sunxi pinctrl has a fixed size array it uses to store regulators used
> in the driver. There is currently nothing that ensures that the number of
> elements in the array is large enough to map the regulators defined by the
> individual SoCs. While this is currently the case having an explicit check
> in there will make life easier for anyone debugging memory issues that
> manifest in the driver so let's add one.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej

> ---
>  drivers/pinctrl/sunxi/pinctrl-sunxi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index 1dc1882cbdd7..1d1cd3d6d379
> 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> @@ -848,6 +848,9 @@ static int sunxi_pmx_request(struct pinctrl_dev
> *pctldev, unsigned offset) char supply[16];
>  	int ret;
> 
> +	if (WARN_ON_ONCE(bank_offset >= ARRAY_SIZE(pctl->regulators)))
> +		return -EINVAL;
> +
>  	if (reg) {
>  		refcount_inc(&s_reg->refcount);
>  		return 0;
> 
> ---
> base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
> change-id: 20230711-pinctrl-sunxi-boudns-95bf5da3d075
> 
> Best regards,





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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array
  2023-07-12 17:19 [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array Mark Brown
  2023-07-12 17:53 ` Jernej Škrabec
@ 2023-07-12 17:57 ` Chen-Yu Tsai
  2023-07-20 19:33 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Chen-Yu Tsai @ 2023-07-12 17:57 UTC (permalink / raw)
  To: Mark Brown
  Cc: Linus Walleij, Jernej Skrabec, Samuel Holland, linux-gpio,
	linux-arm-kernel, linux-sunxi, linux-kernel

On Thu, Jul 13, 2023 at 1:20 AM Mark Brown <broonie@kernel.org> wrote:
>
> The sunxi pinctrl has a fixed size array it uses to store regulators used
> in the driver. There is currently nothing that ensures that the number of
> elements in the array is large enough to map the regulators defined by the
> individual SoCs. While this is currently the case having an explicit check
> in there will make life easier for anyone debugging memory issues that
> manifest in the driver so let's add one.
>
> Signed-off-by: Mark Brown <broonie@kernel.org>

Reviewed-by: Chen-Yu Tsai <wens@csie.org>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array
  2023-07-12 17:19 [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array Mark Brown
  2023-07-12 17:53 ` Jernej Škrabec
  2023-07-12 17:57 ` Chen-Yu Tsai
@ 2023-07-20 19:33 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2023-07-20 19:33 UTC (permalink / raw)
  To: Mark Brown
  Cc: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, linux-gpio,
	linux-arm-kernel, linux-sunxi, linux-kernel

On Wed, Jul 12, 2023 at 7:20 PM Mark Brown <broonie@kernel.org> wrote:

> The sunxi pinctrl has a fixed size array it uses to store regulators used
> in the driver. There is currently nothing that ensures that the number of
> elements in the array is large enough to map the regulators defined by the
> individual SoCs. While this is currently the case having an explicit check
> in there will make life easier for anyone debugging memory issues that
> manifest in the driver so let's add one.
>
> Signed-off-by: Mark Brown <broonie@kernel.org>

Patch applied.

Yours,
Linus Walleij

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-20 19:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-12 17:19 [PATCH] pinctrl: sunxi: Add some defensiveness for regulators array Mark Brown
2023-07-12 17:53 ` Jernej Škrabec
2023-07-12 17:57 ` Chen-Yu Tsai
2023-07-20 19:33 ` Linus Walleij

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).