Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pinctrl: core: handle radix_tree_insert() errors in pinctrl_register_one_pin()

pinctrl_register_one_pin() doesn't check the result of radix_tree_insert()
despite they both may return a negative error code. Linus Walleij said he
has copied the radix tree code from kernel/irq/ where the functions calling
radix_tree_insert() are *void* themselves; I think it makes more sense to
propagate the errors from radix_tree_insert() upstream if we can do that...

Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.

Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/20230719202253.13469-3-s.shtylyov@omp.ru
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Sergey Shtylyov and committed by
Linus Walleij
ecfe9a01 b56e23bf

+11 -3
+11 -3
drivers/pinctrl/core.c
··· 205 205 const struct pinctrl_pin_desc *pin) 206 206 { 207 207 struct pin_desc *pindesc; 208 + int error; 208 209 209 210 pindesc = pin_desc_get(pctldev, pin->number); 210 211 if (pindesc) { ··· 227 226 } else { 228 227 pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", pin->number); 229 228 if (!pindesc->name) { 230 - kfree(pindesc); 231 - return -ENOMEM; 229 + error = -ENOMEM; 230 + goto failed; 232 231 } 233 232 pindesc->dynamic_name = true; 234 233 } 235 234 236 235 pindesc->drv_data = pin->drv_data; 237 236 238 - radix_tree_insert(&pctldev->pin_desc_tree, pin->number, pindesc); 237 + error = radix_tree_insert(&pctldev->pin_desc_tree, pin->number, pindesc); 238 + if (error) 239 + goto failed; 240 + 239 241 pr_debug("registered pin %d (%s) on %s\n", 240 242 pin->number, pindesc->name, pctldev->desc->name); 241 243 return 0; 244 + 245 + failed: 246 + kfree(pindesc); 247 + return error; 242 248 } 243 249 244 250 static int pinctrl_register_pins(struct pinctrl_dev *pctldev,