Input: do not use WARN() in input_alloc_absinfo()
Subsystems (2)
Dmitry Torokhov
maintainerPATCH 1/1 Input: do not use WARN() in input_alloc_absinfo()
Some of fuzzers set panic_on_warn=1 so that they can handle WARN()ings the same way they handle full-blown kernel crashes. We used WARN() in input_alloc_absinfo() to get a better idea where memory allocation failed, but since then kmalloc() and friends started dumping call stack on memory allocation failures anyway, so we are not getting anything extra from WARN().
Because of the above, let's replace WARN with dev_err(). We use dev_err() instead of simply removing message and relying on kcalloc() to give us stack dump so that we'd know the instance of hardware device to which we were trying to attach input device.
--- drivers/input/input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/input/input.c +12 -4
@@ -481,11 +481,19 @@ EXPORT_SYMBOL(input_inject_event);*/ void input_alloc_absinfo (struct input_dev *dev) { -if (!dev->absinfo) - dev->absinfo =kcalloc (ABS_CNT ,sizeof (*dev->absinfo), -GFP_KERNEL ); +if (dev->absinfo) +return ; -WARN (!dev->absinfo,"%s(): kcalloc() failed?\n" , __func__); + dev->absinfo =kcalloc (ABS_CNT ,sizeof (*dev->absinfo),GFP_KERNEL ); +if (!dev->absinfo) { +dev_err (dev->dev.parent ?: &dev->dev, +"%s: unable to allocate memory\n" , __func__); +/* +* We will handle this allocation failure in +* input_register_device() when we refuse to register input +* device with ABS bits but without absinfo. +*/ + } }EXPORT_SYMBOL (input_alloc_absinfo);
Signature · 5 lines
2.18.0.597.ga71716f1ad-goog -- Dmitry
Quoted 35 lines · Dmitry Torokhov
Some of fuzzers set panic_on_warn=1 so that they can handle WARN()ings the same way they handle full-blown kernel crashes. We used
WARN()ininput_alloc_absinfo()to get a better idea where memory allocation failed, but since thenkmalloc()and friends started dumping call stack on memory allocation failures anyway, so we are not getting anything extra fromWARN().Because of the above, let's replace WARN with
dev_err(). We usedev_err()instead of simply removing message and relying onkcalloc()to give us stack dump so that we'd know the instance of hardware device to which we were trying to attach input device.Reported-by Dmitry Vyukov <[email protected]>Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/input/input.c +4
-4@@ -481,11 +481,19 @@ EXPORT_SYMBOL(input_inject_event);*/ void input_alloc_absinfo (struct input_dev *dev) { -if (!dev->absinfo) - dev->absinfo =kcalloc (ABS_CNT ,sizeof (*dev->absinfo), -GFP_KERNEL ); +if (dev->absinfo) +return ; -WARN (!dev->absinfo,"%s(): kcalloc() failed?\n" , __func__); + dev->absinfo =kcalloc (ABS_CNT ,sizeof (*dev->absinfo),GFP_KERNEL ); +if (!dev->absinfo) {
drivers/input/input.c EXPORT_SYMBOL(input_inject_event); · line 498
Quoted 10 lines
drivers/input/input.c +8
-0+dev_err (dev->dev.parent ?: &dev->dev, +"%s: unable to allocate memory\n" , __func__); +/* +* We will handle this allocation failure in +* input_register_device() when we refuse to register input +* device with ABS bits but without absinfo. +*/ + } }EXPORT_SYMBOL (input_alloc_absinfo);
Thanks!