Skip to content

Commit 7f57871

Browse files
Colin Ian KingLinus Walleij
authored andcommitted
pinctrl: single: Add allocation failure checking of saved_vals
Currently saved_vals is being allocated and there is no check for failed allocation (which is more likely than normal when using GFP_ATOMIC). Fix this by checking for a failed allocation and propagating this error return down the the caller chain. Detected by CoverityScan, CID#1469841 ("Dereference null return value") Fixes: 88a1dbd ("pinctrl: pinctrl-single: Add functions to save and restore pinctrl context") Signed-off-by: Colin Ian King <colin.king@canonical.com> Reviewed-by: Johan Hovold <johan@kernel.org> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent bc3322b commit 7f57871

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎drivers/pinctrl/pinctrl-single.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,11 @@ static int pcs_save_context(struct pcs_device *pcs)
15901590

15911591
mux_bytes = pcs->width / BITS_PER_BYTE;
15921592

1593-
if (!pcs->saved_vals)
1593+
if (!pcs->saved_vals) {
15941594
pcs->saved_vals = devm_kzalloc(pcs->dev, pcs->size, GFP_ATOMIC);
1595+
if (!pcs->saved_vals)
1596+
return -ENOMEM;
1597+
}
15951598

15961599
switch (pcs->width) {
15971600
case 64:
@@ -1651,8 +1654,13 @@ static int pinctrl_single_suspend(struct platform_device *pdev,
16511654
if (!pcs)
16521655
return -EINVAL;
16531656

1654-
if (pcs->flags & PCS_CONTEXT_LOSS_OFF)
1655-
pcs_save_context(pcs);
1657+
if (pcs->flags & PCS_CONTEXT_LOSS_OFF) {
1658+
int ret;
1659+
1660+
ret = pcs_save_context(pcs);
1661+
if (ret < 0)
1662+
return ret;
1663+
}
16561664

16571665
return pinctrl_force_sleep(pcs->pctl);
16581666
}

0 commit comments

Comments
 (0)