2022-05-02 01:53:08

by CGEL

[permalink] [raw]
Subject: [PATCH] Input: simplify the return expression of da9034_touch_probe()

From: Minghao Chi <[email protected]>

Simplify the return expression.

Reported-by: Zeal Robot <[email protected]>
Signed-off-by: Minghao Chi <[email protected]>
---
drivers/input/touchscreen/da9034-ts.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/input/touchscreen/da9034-ts.c b/drivers/input/touchscreen/da9034-ts.c
index 2943f6a58388..dfb2604381d2 100644
--- a/drivers/input/touchscreen/da9034-ts.c
+++ b/drivers/input/touchscreen/da9034-ts.c
@@ -298,7 +298,6 @@ static int da9034_touch_probe(struct platform_device *pdev)
struct da9034_touch_pdata *pdata = dev_get_platdata(&pdev->dev);
struct da9034_touch *touch;
struct input_dev *input_dev;
- int error;

touch = devm_kzalloc(&pdev->dev, sizeof(struct da9034_touch),
GFP_KERNEL);
@@ -344,11 +343,7 @@ static int da9034_touch_probe(struct platform_device *pdev)
touch->input_dev = input_dev;
input_set_drvdata(input_dev, touch);

- error = input_register_device(input_dev);
- if (error)
- return error;
-
- return 0;
+ return input_register_device(input_dev);
}

static struct platform_driver da9034_touch_driver = {
--
2.25.1



2022-05-12 20:09:07

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] Input: simplify the return expression of da9034_touch_probe()

On Fri, Apr 29, 2022 at 05:53:00AM +0000, [email protected] wrote:
> From: Minghao Chi <[email protected]>
>
> Simplify the return expression.
>
> Reported-by: Zeal Robot <[email protected]>
> Signed-off-by: Minghao Chi <[email protected]>
> ---
> drivers/input/touchscreen/da9034-ts.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/input/touchscreen/da9034-ts.c b/drivers/input/touchscreen/da9034-ts.c
> index 2943f6a58388..dfb2604381d2 100644
> --- a/drivers/input/touchscreen/da9034-ts.c
> +++ b/drivers/input/touchscreen/da9034-ts.c
> @@ -298,7 +298,6 @@ static int da9034_touch_probe(struct platform_device *pdev)
> struct da9034_touch_pdata *pdata = dev_get_platdata(&pdev->dev);
> struct da9034_touch *touch;
> struct input_dev *input_dev;
> - int error;
>
> touch = devm_kzalloc(&pdev->dev, sizeof(struct da9034_touch),
> GFP_KERNEL);
> @@ -344,11 +343,7 @@ static int da9034_touch_probe(struct platform_device *pdev)
> touch->input_dev = input_dev;
> input_set_drvdata(input_dev, touch);
>
> - error = input_register_device(input_dev);
> - if (error)
> - return error;
> -
> - return 0;
> + return input_register_device(input_dev);

In cases where there are multiple checks/exit paths in the same function
I prefer the existing style as it requires less changes when extending.

Thanks,

--
Dmitry