gpiolib: don't report -ENOMEM for a requested line without a label
Subsystems (2)
PATCH 1/1 gpiolib: don't report -ENOMEM for a requested line without a label
gpiod_request_commit() sets GPIOD_FLAG_REQUESTED, calls ->request() and only then sets the label. A line in between has no label, so gpiochip_dup_line_label() passes NULL to kstrdup() and returns ERR_PTR(-ENOMEM), which for_each_hwgpio() then passes to kfree():
BUG: unable to handle page fault for address: ffcc73074355ffc8 Call Trace: gpio_sim_dbg_show gpiolib_seq_show seq_read_iter
Return NULL for such a line, as for an unrequested one.
Reproduced with gpio-sim: reading /sys/kernel/debug/gpio in a loop while lines are requested and released oopses within seconds; with this change, 100000 cycles pass.
--- drivers/gpio/gpiolib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +6 -1
@@ -2721,6 +2721,7 @@ void gpiod_free(struct gpio_desc *desc)char *gpiochip_dup_line_label (struct gpio_chip *gc,unsigned int offset) {struct gpio_desc *desc; +const char *name;char *label; desc =gpiochip_get_desc (gc, offset);
@@ -2732,7 +2733,11 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset)guard (srcu)(&desc->gdev->desc_srcu); - label =kstrdup (gpiod_get_label (desc),GFP_KERNEL ); + name =gpiod_get_label (desc); +if (!name) +return NULL ; + + label =kstrdup (name,GFP_KERNEL );if (!label)return ERR_PTR (-ENOMEM );
base-commit: a0fe269293509acdd93b9cfb3f46636f7b91b33a
Signature · 1 line
2.43.0
Bartosz Golaszewski
AppliedQuoted 5 lines · Adrian Ambrozewicz
gpiod_request_commit()setsGPIOD_FLAG_REQUESTED, calls ->request() and only then sets the label. A line in between has no label, sogpiochip_dup_line_label()passes NULL tokstrdup()and returnsERR_PTR(-ENOMEM), whichfor_each_hwgpio()then passes tokfree():
Quoted 7 lines
BUG: unable to handle page fault for address: ffcc73074355ffc8 Call Trace: gpio_sim_dbg_show gpiolib_seq_show seq_read_iter[...]
Applied, thanks!
[1/1] gpiolib: don't report -ENOMEM for a requested line without a label
https://git.kernel.org/brgl/c/dae739137441667d67fbfcc4d303a0ecc6618662
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>