staging: nvec: kbd: use -EINVAL instead of -1
Subsystems (3)
PATCH 1/1 staging: nvec: kbd: use -EINVAL instead of -1
Return proper error code -EINVAL instead of -1 when the event type or code is not supported.
--- drivers/staging/nvec/nvec_kbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/nvec/nvec_kbd.c +2 -2
@@ -92,10 +92,10 @@ static int nvec_kbd_event(struct input_dev *dev, unsigned int type,return 0 ;if (type !=EV_LED ) -return -1 ; +return -EINVAL ;if (code !=LED_CAPSL ) -return -1 ; +return -EINVAL ; buf[2 ] = !!value;nvec_write_async (nvec, buf,sizeof (buf));
Signature · 1 line
2.34.1
Quoted 5 lines · Soham Kute
Return proper error code
-EINVALinstead of -1 when the event type or code is not supported.Signed-off-by Soham Kute <[email protected]>---
Could you do some analysis to see if this affects runtime? You'll need to review the callers to see what they do with error codes. In this case they ignore them.
One thing which could help would be to build the Smatch cross function DB. But it takes a long time so do it overnight.
https://github.com/error27/smatch
https://github.com/error27/smatch/blob/master/Documentation/smatch.rst
cd ~/path/to/kernel_dir ~/path/to/smatch_dir/smatch_scripts/build_kernel_data.sh
$ ~/progs/smatch/devel/smatch_data/db/smdb.py nvec_kbd_event | grep INTER drivers/input/input.c | input_event_dispose | (struct input_dev)->event | INTERNAL | -1 | | int(*)(struct input_dev*, uint, uint, int) drivers/input/input.c | input_dev_toggle | (struct input_dev)->event | INTERNAL | -1 | | int(*)(struct input_dev*, uint, uint, int) drivers/input/input.c | input_dev_toggle | (struct input_dev)->event | INTERNAL | -1 | | int(*)(struct input_dev*, uint, uint, int) drivers/input/input.c | input_dev_toggle | (struct input_dev)->event | INTERNAL | -1 | | int(*)(struct input_dev*, uint, uint, int) drivers/input/input.c | input_dev_toggle | (struct input_dev)->event | INTERNAL | -1 | | int(*)(struct input_dev*, uint, uint, int) drivers/hid/hid-holtek-kbd.c | holtek_kbd_input_event | (struct input_dev)->event | INTERNAL | -1 | | int(*)(struct input_dev*, uint, uint, int) $
regards,
dan carpenter
Hi Dan,
Thanks for pointing me to smatch. I built the DB and ran the queries.
From what I can see, dev->event() is called in input_handle_event() but the return value is not propagated back up. The smatch caller_info table shows type INTERNAL for that call which I understand means the return value stays internal and never reaches the caller of input_event().
So yes, this patch has no runtime effect. The reason I sent it was that pcspkr.c uses -EINVAL in the same type of event callback, so I thought nvec_kbd should be consistent with that.
Also noticed atkbd.c has the same -1 in its event callback. Should I send a fix for that too?
Best regards,
Soham
Quoted 5 lines · Soham Kute
Hi Dan,
Thanks for pointing me to smatch. I built the DB and ran the queries.
Quoted 1 line
From what I can see,
dev->event()is called ininput_handle_event()
Quoted 8 lines
but the return value is not propagated back up. The smatch
caller_infotable shows type INTERNAL for that call which I understand means the return value stays internal and never reaches the caller ofinput_event().So yes, this patch has no runtime effect. The reason I sent it was that
pcspkr.cuses-EINVALin the same type of event callback, so I thoughtnvec_kbdshould be consistent with that.
Put that kind of thing in the commit message.
"This patch has no effect on runtime but returning proper error codes is the correct thing and it makes it more consistent with other functions that implement it such whatever_function() in pcspkr.c"
Quoted 3 lines
Also noticed
atkbd.chas the same -1 in its event callback. Should I send a fix for that too?
If you want to do that, then sure, absolutely.
regards,
dan carpenter