linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: ralink: Check for null return of devm_kcalloc
@ 2022-07-10 15:49 williamsukatube
  2022-07-11 12:42 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: williamsukatube @ 2022-07-10 15:49 UTC (permalink / raw)
  To: arinc.unal, sergio.paracuellos, linus.walleij, linux-mips,
	linux-gpio, linux-kernel
  Cc: William Dean, Hacash Robot

From: William Dean <williamsukatube@gmail.com>

Because of the possible failure of the allocation, data->domains might
be NULL pointer and will cause the dereference of the NULL pointer
later.
Therefore, it might be better to check it and directly return -ENOMEM
without releasing data manually if fails, because the comment of the
devm_kmalloc() says "Memory allocated with this function is
automatically freed on driver detach.".

Fixes: a86854d0c599b ("treewide: devm_kzalloc() -> devm_kcalloc()")
Reported-by: Hacash Robot <hacashRobot@santino.com>
Signed-off-by: William Dean <williamsukatube@gmail.com>
---
 drivers/pinctrl/ralink/pinctrl-ralink.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/ralink/pinctrl-ralink.c b/drivers/pinctrl/ralink/pinctrl-ralink.c
index 63429a287434..770862f45b3f 100644
--- a/drivers/pinctrl/ralink/pinctrl-ralink.c
+++ b/drivers/pinctrl/ralink/pinctrl-ralink.c
@@ -266,6 +266,8 @@ static int ralink_pinctrl_pins(struct ralink_priv *p)
 						p->func[i]->pin_count,
 						sizeof(int),
 						GFP_KERNEL);
+		if (!p->func[i]->pins)
+			return -ENOMEM;
 		for (j = 0; j < p->func[i]->pin_count; j++)
 			p->func[i]->pins[j] = p->func[i]->pin_first + j;
 
-- 
2.25.1


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

* Re: [PATCH] pinctrl: ralink: Check for null return of devm_kcalloc
  2022-07-10 15:49 [PATCH] pinctrl: ralink: Check for null return of devm_kcalloc williamsukatube
@ 2022-07-11 12:42 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2022-07-11 12:42 UTC (permalink / raw)
  To: williamsukatube
  Cc: arinc.unal, sergio.paracuellos, linux-mips, linux-gpio,
	linux-kernel, William Dean, Hacash Robot

On Sun, Jul 10, 2022 at 5:49 PM <williamsukatube@163.com> wrote:

> From: William Dean <williamsukatube@gmail.com>
>
> Because of the possible failure of the allocation, data->domains might
> be NULL pointer and will cause the dereference of the NULL pointer
> later.
> Therefore, it might be better to check it and directly return -ENOMEM
> without releasing data manually if fails, because the comment of the
> devm_kmalloc() says "Memory allocated with this function is
> automatically freed on driver detach.".
>
> Fixes: a86854d0c599b ("treewide: devm_kzalloc() -> devm_kcalloc()")
> Reported-by: Hacash Robot <hacashRobot@santino.com>
> Signed-off-by: William Dean <williamsukatube@gmail.com>

Patch applied for fixes!

Yours,
Linus Walleij

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

end of thread, other threads:[~2022-07-11 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-10 15:49 [PATCH] pinctrl: ralink: Check for null return of devm_kcalloc williamsukatube
2022-07-11 12:42 ` 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).