Skip to contentSkip to conversation

staging: nvec: kbd: use -EINVAL instead of -1

PATCH In review Soham Kute 2 participants 4 messages Feb 28 – Mar 4

Subsystems (3)
lore
Share & tools
lore

Soham Kute

author
#0 lore raw

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
index d2b91318f151..5f742c8b32cc 100644
@@ -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
#1 lore raw
Quoted 5 lines · Soham Kute

Return proper error code -EINVAL instead of -1 when the event type or code is not supported.

---

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

author
#2 lore raw

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

#3 lore raw
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 in input_handle_event()

Quoted 8 lines

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.

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.c has 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