Handle errors returned by radix_tree_insert() within drivers/pinctrl/
Subsystems (2)
cover Handle errors returned by radix_tree_insert() within drivers/pinctrl/
Here are 3 patches against the 'devel' branch of Linus W.'s 'linux-pinctrl.git' repo...
The code in drivers/pinctrl/ doesn't check the results of radix_tree_insert() calls, although it could propagate the errors from the callers upstream. (Linus Walleij said he has copied the radix tree code from kernel/irq/, where the functions calling radix_tree_insert() are *void* themselves.)
Sergey Shtylyov (3):
pinctrl: core: handle radix_tree_insert() errors in
pinctrl_generic_add_group()
pinctrl: core: handle radix_tree_insert() errors in
pinctrl_register_one_pin()
pinctrl: pinmux: handle radix_tree_insert() errors in
pinmux_generic_add_function()
drivers/pinctrl/core.c | 20 +++++++++++++++----- drivers/pinctrl/pinmux.c | 6 ++++-- 2 files changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
2.26.3
PATCH 1/3 pinctrl: core: handle radix_tree_insert() errors in pinctrl_generic_add_group()
pinctrl_generic_add_group() 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.
--- drivers/pinctrl/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pinctrl/core.c +4 -2
@@ -633,7 +633,7 @@ int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name, int *pins, int num_pins, void *data) { struct group_desc *group; -int selector; +int selector, error;if (!name)return -EINVAL ;
@@ -653,7 +653,9 @@ int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name, group->num_pins = num_pins; group->data = data; -radix_tree_insert (&pctldev->pin_group_tree, selector, group); + error =radix_tree_insert (&pctldev->pin_group_tree, selector, group); +if (error) +return error; pctldev->num_groups++;
Signature · 1 line
2.26.3
PATCH 2/3 pinctrl: core: handle radix_tree_insert() errors in pinctrl_register_one_pin()
In reply to Sergey Shtylyovpinctrl_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.
--- drivers/pinctrl/core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/pinctrl/core.c +11 -3
@@ -205,6 +205,7 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev, const struct pinctrl_pin_desc *pin) {struct pin_desc *pindesc; +int error; pindesc =pin_desc_get (pctldev, pin->number);if (pindesc) {
@@ -226,18 +227,25 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev, }else { pindesc->name =kasprintf (GFP_KERNEL ,"PIN%u" , pin->number);if (!pindesc->name) { -kfree (pindesc); -return -ENOMEM ; + error = -ENOMEM ; + goto failed; } pindesc->dynamic_name = true; } pindesc->drv_data = pin->drv_data; -radix_tree_insert (&pctldev->pin_desc_tree, pin->number, pindesc); + error =radix_tree_insert (&pctldev->pin_desc_tree, pin->number, pindesc); +if (error) + goto failed; +pr_debug ("registered pin %d (%s) on %s\n" , pin->number, pindesc->name, pctldev->desc->name);return 0 ; + +failed: +kfree (pindesc); +return error; } static int pinctrl_register_pins(struct pinctrl_dev *pctldev,
Signature · 1 line
2.26.3
PATCH 3/3 pinctrl: pinmux: handle radix_tree_insert() errors in pinmux_generic_add_function()
In reply to Sergey Shtylyovpinctrl_generic_add_function() doesn't check 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.
--- drivers/pinctrl/pinmux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pinctrl/pinmux.c +4 -2
@@ -872,7 +872,7 @@ int pinmux_generic_add_function(struct pinctrl_dev *pctldev, void *data) {struct function_desc *function; -int selector; +int selector, error;if (!name)return -EINVAL ;
@@ -892,7 +892,9 @@ int pinmux_generic_add_function(struct pinctrl_dev *pctldev, function->num_group_names = num_groups; function->data = data; -radix_tree_insert (&pctldev->pin_function_tree, selector, function); + error =radix_tree_insert (&pctldev->pin_function_tree, selector, function); +if (error) +return error; pctldev->num_functions++;
Signature · 1 line
2.26.3
Quoted 4 lines · Sergey Shtylyov
The code in
drivers/pinctrl/doesn't check the results ofradix_tree_insert()calls, although it could propagate the errors from the callers upstream. (Linus Walleij said he has copied the radix tree code fromkernel/irq/, where the functions callingradix_tree_insert()are *void* themselves.)
The fix is spot on.
Patches applied!
Yours,
Linus Walleij
On 7/28/23 11:09 PM, Linus Walleij wrote:
[...]
Quoted 7 lines
Quoted 4 lines
The code in
drivers/pinctrl/doesn't check the results ofradix_tree_insert()calls, although it could propagate the errors from the callers upstream. (Linus Walleij said he has copied the radix tree code fromkernel/irq/, where the functions callingradix_tree_insert()are *void* themselves.)The fix is spot on.
Patches applied!
Thank you!
But to which branch?
Quoted 2 lines
Yours,
Linus Walleij
MBR, Sergey