lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z0TO/OL5DQWSMLfG@lizhi-Precision-Tower-5810>
Date: Mon, 25 Nov 2024 14:24:44 -0500
From: Frank Li <Frank.li@....com>
To: Jonathan Cameron <jic23@...nel.org>
Cc: Haibo Chen <haibo.chen@....com>, Lars-Peter Clausen <lars@...afoo.de>,
	"open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER" <linux-iio@...r.kernel.org>,
	"open list:NXP i.MX 7D/6SX/6UL/93 AND VF610 ADC DRIVER" <imx@...ts.linux.dev>,
	open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 1/2] iio: adc: vf610_adc: use devm_* and
 dev_err_probe() to simple code

On Sat, Nov 23, 2024 at 03:26:37PM +0000, Jonathan Cameron wrote:
> On Mon, 11 Nov 2024 16:38:58 -0500
> Frank Li <Frank.Li@....com> wrote:
>
> > Use devm_* and dev_err_probe() simplify probe function and remove
> > vf610_adc_remove().
> >
> > Reviewed-by: Haibo Chen <haibo.chen@....com>
> > Signed-off-by: Frank Li <Frank.Li@....com>
> Hi Frank,
>
> One (hopefully final) question inline.
>
> Jonathan
>
> > ---
> > Change from v3 to v4
> > - keep vref_uv as u32
> > - keep original regulator part and only add
> > devm_add_action_or_reset(&pdev->dev, vf610_adc_remove, info)
> >
> > Change from v2 to v3
> > - change vref_uv to int from u32 to fix below warning
> > | Reported-by: kernel test robot <lkp@...el.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202411070633.NIrO7Ert-lkp@intel.com/
> > smatch warnings:
> > drivers/iio/adc/vf610_adc.c:857 vf610_adc_probe() warn: unsigned 'info->vref_uv' is never less than zero.
> >
> > vim +857 drivers/iio/adc/vf610_adc.c
> >
> > Change from v1 to v2
> > - add Haibo's review tag
> > ---
> >  drivers/iio/adc/vf610_adc.c | 79 ++++++++++++-------------------------
> >  1 file changed, 26 insertions(+), 53 deletions(-)
> >
> > diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
> > index 4d83c12975c53..d4b778799755b 100644
> > --- a/drivers/iio/adc/vf610_adc.c
> > +++ b/drivers/iio/adc/vf610_adc.c
> > @@ -814,6 +814,14 @@ static const struct of_device_id vf610_adc_match[] = {
> >  };
> >  MODULE_DEVICE_TABLE(of, vf610_adc_match);
> >
> > +static void vf610_adc_action_remove(void *d)
> > +{
> > +	struct vf610_adc *info = d;
> > +
> > +	if (info->vref)
> > +		regulator_disable(info->vref);
>
> Why is the check on info->vref needed?
> vref is required to reach the point where this callback is registered.
>
> > +}
> > +
> >  static int vf610_adc_probe(struct platform_device *pdev)
> >  {
> >  	struct device *dev = &pdev->dev;
> > @@ -823,10 +831,8 @@ static int vf610_adc_probe(struct platform_device *pdev)
> >  	int ret;
> >
> >  	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct vf610_adc));
> > -	if (!indio_dev) {
> > -		dev_err(&pdev->dev, "Failed allocating iio device\n");
> > -		return -ENOMEM;
> > -	}
> > +	if (!indio_dev)
> > +		return dev_err_probe(&pdev->dev, -ENOMEM, "Failed allocating iio device\n");
> >
> >  	info = iio_priv(indio_dev);
> >  	info->dev = &pdev->dev;
> > @@ -842,17 +848,12 @@ static int vf610_adc_probe(struct platform_device *pdev)
> >  	ret = devm_request_irq(info->dev, irq,
> >  				vf610_adc_isr, 0,
> >  				dev_name(&pdev->dev), indio_dev);
> > -	if (ret < 0) {
> > -		dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
> > -		return ret;
> > -	}
> > +	if (ret < 0)
> > +		return dev_err_probe(&pdev->dev, ret, "failed requesting irq, irq = %d\n", irq);
> >
> > -	info->clk = devm_clk_get(&pdev->dev, "adc");
> > -	if (IS_ERR(info->clk)) {
> > -		dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
> > -						PTR_ERR(info->clk));
> > -		return PTR_ERR(info->clk);
> > -	}
> > +	info->clk = devm_clk_get_enabled(&pdev->dev, "adc");
> > +	if (IS_ERR(info->clk))
> > +		return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), "failed getting clock\n");
> >
> >  	info->vref = devm_regulator_get(&pdev->dev, "vref");
> >  	if (IS_ERR(info->vref))
> > @@ -862,6 +863,10 @@ static int vf610_adc_probe(struct platform_device *pdev)
> >  	if (ret)
> >  		return ret;
> >
> > +	ret = devm_add_action_or_reset(&pdev->dev, vf610_adc_action_remove, info);
>
> As above, but this time if info->vref is not set, we have already returned so it
> must be set and doesn't need checking the callback.

Yes, you are right. Needn't check it at callback.

Frank
>
> > +	if (ret)
> > +		return ret;
> > +
> >  	info->vref_uv = regulator_get_voltage(info->vref);
> >
> >  	device_property_read_u32_array(dev, "fsl,adck-max-frequency", info->max_adck_rate, 3);
> > @@ -879,52 +884,21 @@ static int vf610_adc_probe(struct platform_device *pdev)
> >  	indio_dev->channels = vf610_adc_iio_channels;
> >  	indio_dev->num_channels = ARRAY_SIZE(vf610_adc_iio_channels);
> >
> > -	ret = clk_prepare_enable(info->clk);
> > -	if (ret) {
> > -		dev_err(&pdev->dev,
> > -			"Could not prepare or enable the clock.\n");
> > -		goto error_adc_clk_enable;
> > -	}
> > -
> >  	vf610_adc_cfg_init(info);
> >  	vf610_adc_hw_init(info);
> >
> > -	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> > -					NULL, &iio_triggered_buffer_setup_ops);
> > -	if (ret < 0) {
> > -		dev_err(&pdev->dev, "Couldn't initialise the buffer\n");
> > -		goto error_iio_device_register;
> > -	}
> > +	ret = devm_iio_triggered_buffer_setup(&pdev->dev, indio_dev, &iio_pollfunc_store_time,
> > +					      NULL, &iio_triggered_buffer_setup_ops);
> > +	if (ret < 0)
> > +		return dev_err_probe(&pdev->dev, ret, "Couldn't initialise the buffer\n");
> >
> >  	mutex_init(&info->lock);
> >
> > -	ret = iio_device_register(indio_dev);
> > -	if (ret) {
> > -		dev_err(&pdev->dev, "Couldn't register the device.\n");
> > -		goto error_adc_buffer_init;
> > -	}
> > +	ret = devm_iio_device_register(&pdev->dev, indio_dev);
> > +	if (ret)
> > +		return dev_err_probe(&pdev->dev, ret, "Couldn't register the device.\n");
> >
> >  	return 0;
> > -
> > -error_adc_buffer_init:
> > -	iio_triggered_buffer_cleanup(indio_dev);
> > -error_iio_device_register:
> > -	clk_disable_unprepare(info->clk);
> > -error_adc_clk_enable:
> > -	regulator_disable(info->vref);
> > -
> > -	return ret;
> > -}
> > -
> > -static void vf610_adc_remove(struct platform_device *pdev)
> > -{
> > -	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
> > -	struct vf610_adc *info = iio_priv(indio_dev);
> > -
> > -	iio_device_unregister(indio_dev);
> > -	iio_triggered_buffer_cleanup(indio_dev);
> > -	regulator_disable(info->vref);
> > -	clk_disable_unprepare(info->clk);
> >  }
> >
> >  static int vf610_adc_suspend(struct device *dev)
> > @@ -972,7 +946,6 @@ static DEFINE_SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend,
> >
> >  static struct platform_driver vf610_adc_driver = {
> >  	.probe          = vf610_adc_probe,
> > -	.remove         = vf610_adc_remove,
> >  	.driver         = {
> >  		.name   = DRIVER_NAME,
> >  		.of_match_table = vf610_adc_match,
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ