diff mbox

[1/1] pinctrl: sunxi: Fix potential null pointer dereference

Message ID 1401445252-21413-1-git-send-email-sachin.kamat@linaro.org
State Accepted
Commit bd07894e217b174361711320be50c8308456096d
Headers show

Commit Message

Sachin Kamat May 30, 2014, 10:20 a.m. UTC
kzalloc can fail. Add a null check to avoid null pointer
dereference error while accessing the pointer later.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c |    4 ++++
 1 file changed, 4 insertions(+)

Comments

Maxime Ripard June 2, 2014, 9:39 a.m. UTC | #1
On Fri, May 30, 2014 at 03:50:52PM +0530, Sachin Kamat wrote:
> kzalloc can fail. Add a null check to avoid null pointer
> dereference error while accessing the pointer later.
> 
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime
Linus Walleij June 9, 2014, 1:16 p.m. UTC | #2
On Fri, May 30, 2014 at 12:20 PM, Sachin Kamat <sachin.kamat@linaro.org> wrote:

> kzalloc can fail. Add a null check to avoid null pointer
> dereference error while accessing the pointer later.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>

Patch applied for fixes with Maxime's ACK.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index f1ca75e6d7b1..5f38c7f67834 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -211,6 +211,10 @@  static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 			configlen++;
 
 		pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL);
+		if (!pinconfig) {
+			kfree(*map);
+			return -ENOMEM;
+		}
 
 		if (!of_property_read_u32(node, "allwinner,drive", &val)) {
 			u16 strength = (val + 1) * 10;