PCI/sysfs: Return -EINVAL consistently from "store" functions
authorKrzysztof Wilczyński <kw@linux.com>
Wed, 15 Sep 2021 23:01:26 +0000 (23:01 +0000)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 28 Sep 2021 22:47:04 +0000 (17:47 -0500)
commit36f354ec7bf92f8aaf09eaf3b261ea06c25ec337
tree6a47d7f45c4eec63663b01bce08ee9991c3c4890
parent95e83e219d68956ba4fed9326683e4d2bd3e39a9
PCI/sysfs: Return -EINVAL consistently from "store" functions

Most of the "store" functions that handle userspace input via sysfs return
-EINVAL should the value fail validation and/or type conversion.  This
error code is a clear message to userspace that the value is not a valid
input.

However, some of the "show" functions return input parsing error codes
as-is, which may be either -EINVAL or -ERANGE.  The former would often be
from kstrtobool(), and the latter typically from other kstr*() functions
such as kstrtou8(), kstrtou32(), kstrtoint(), etc.

-EINVAL is commonly returned as the error code to indicate that the value
provided is invalid, but -ERANGE is not very useful in userspace.

Therefore, normalize the return error code to be -EINVAL for when the
validation and/or type conversion fails.

Link: https://lore.kernel.org/r/20210915230127.2495723-2-kw@linux.com
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/endpoint/functions/pci-epf-ntb.c
drivers/pci/endpoint/pci-ep-cfs.c
drivers/pci/iov.c
drivers/pci/pci-sysfs.c