Re: [PATCH v3 2/7] Input: mc13783-pwrbutton: use managed resources

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 29, 2025 at 08:15:12PM +0000, Alexander Kurz wrote:
> Use devres functionality to simplify resource freeing, dev.parent will
> be set by devm_input_allocate_device().
> 
> Signed-off-by: Alexander Kurz <akurz@xxxxxxxx>
> ---
>  drivers/input/misc/mc13783-pwrbutton.c | 28 ++++++++------------------
>  1 file changed, 8 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> index 4765b25bc9f6..9fd84b8d163d 100644
> --- a/drivers/input/misc/mc13783-pwrbutton.c
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -21,6 +21,7 @@
>  
>  #include <linux/module.h>
>  #include <linux/kernel.h>
> +#include <linux/device.h>
>  #include <linux/errno.h>
>  #include <linux/input.h>
>  #include <linux/interrupt.h>
> @@ -118,18 +119,13 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> -	pwr = input_allocate_device();
> -	if (!pwr) {
> -		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +	pwr = devm_input_allocate_device(&pdev->dev);
> +	if (!pwr)
>  		return -ENOMEM;
> -	}
>  
> -	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> -	if (!priv) {
> -		err = -ENOMEM;
> -		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> -		goto free_input_dev;
> -	}
> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
>  
>  	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
>  	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
> @@ -155,7 +151,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
>  					  button1_irq, "b1on", priv);
>  		if (err) {
>  			dev_dbg(&pdev->dev, "Can't request irq\n");
> -			goto free_priv;
> +			goto free_mc13xxx_lock;
>  		}
>  	}
>  
> @@ -203,7 +199,6 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
>  
>  	pwr->name = "mc13783_pwrbutton";
>  	pwr->phys = "mc13783_pwrbutton/input0";
> -	pwr->dev.parent = &pdev->dev;
>  
>  	pwr->keycode = priv->keymap;
>  	pwr->keycodemax = ARRAY_SIZE(priv->keymap);
> @@ -234,12 +229,8 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
>  	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
>  		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);

mc13xxx_irq_request() uses devm so you can drop calls to
mc13xxx_irq_free() in both error paths and in remove().

This comment is pretty much moot if you follow my suggestion of using
resources to pass interrupts to the child device.

Thanks.

-- 
Dmitry




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux