drivers/input/joystick/psxpad-spi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Add check for the return value of spi_setup() and return the error
if it fails in order to catch the error.
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
drivers/input/joystick/psxpad-spi.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/input/joystick/psxpad-spi.c b/drivers/input/joystick/psxpad-spi.c
index c47fc5f34bd0..5b53d43c797a 100644
--- a/drivers/input/joystick/psxpad-spi.c
+++ b/drivers/input/joystick/psxpad-spi.c
@@ -344,7 +344,11 @@ static int psxpad_spi_probe(struct spi_device *spi)
/* (PlayStation 1/2 joypad might be possible works 250kHz/500kHz) */
spi->controller->min_speed_hz = 125000;
spi->controller->max_speed_hz = 125000;
- spi_setup(spi);
+ err = spi_setup(spi);
+ if (err < 0) {
+ dev_err(&spi->dev, "failed to set up spi: %d\n", err);
+ return err;
+ }
/* pad settings */
psxpad_set_motor_level(pad, 0, 0);
--
2.25.1
Hello,
[Cc += linux-spi]
On Fri, Jul 05, 2024 at 04:20:57PM +0800, Chen Ni wrote:
> Add check for the return value of spi_setup() and return the error
> if it fails in order to catch the error.
Does this fix a real-world problem, or did you notice this using a
linter or by just reading through the driver?
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
> drivers/input/joystick/psxpad-spi.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/joystick/psxpad-spi.c b/drivers/input/joystick/psxpad-spi.c
> index c47fc5f34bd0..5b53d43c797a 100644
> --- a/drivers/input/joystick/psxpad-spi.c
> +++ b/drivers/input/joystick/psxpad-spi.c
> @@ -344,7 +344,11 @@ static int psxpad_spi_probe(struct spi_device *spi)
> /* (PlayStation 1/2 joypad might be possible works 250kHz/500kHz) */
> spi->controller->min_speed_hz = 125000;
> spi->controller->max_speed_hz = 125000;
> - spi_setup(spi);
> + err = spi_setup(spi);
> + if (err < 0) {
> + dev_err(&spi->dev, "failed to set up spi: %d\n", err);
> + return err;
Please consider using dev_err_probe() in such cases. It allows for a
more compact error path and emits the error code in a human readable
way.
Apart from that: spi_setup() is inconsistent as it emits error messages
for some error paths but not for all. Probably the better change is to
make spi_setup() consistent here. I suggest to add error messages to the
error paths that currently don't have a message and drop this patch.
Best regards
Uwe
© 2016 - 2026 Red Hat, Inc.