Re: [PATCH v2 2/2] iio: gyro: hid-sensor-gyro-3d: Use dev_err_probe()

Jonathan Cameron <[email protected]>
Newsgroups org.kernel.vger.linux-input,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <20260727022546.6d5336e6@jic23-huawei>
On Fri, 24 Jul 2026 22:57:21 +0530
Sanjay Chitroda via B4 Relay <[email protected]> wrote:

> From: Sanjay Chitroda <[email protected]>
> 
> Replace dev_err() calls with dev_err_probe() during probe.
> 
> dev_err_probe() makes error code handling simpler and handle
> deferred probe nicely (avoid spamming logs).

There are changes in here that aren't mentioned.

A common way to handle this is to add.  

"To simplify the added dev_err_probe() calls, add a local struct devic
 variable." 

Then in a follow up patch do the rest and state something like

"Use the local struct device *dev to replace &pdev->dev, simplifying
code."

> 
> Signed-off-by: Sanjay Chitroda <[email protected]>
> ---
>  drivers/iio/gyro/hid-sensor-gyro-3d.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index bcf53e267701..749a2ecbc2d1 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -264,13 +264,14 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
>  /* Function to initialize the processing for usage id */
>  static int hid_gyro_3d_probe(struct platform_device *pdev)
>  {
> -	struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev);
> +	struct device *dev = &pdev->dev;
> +	struct hid_sensor_hub_device *hsdev = dev_get_platdata(dev);
>  	int ret = 0;
>  	static const char *name = "gyro_3d";
>  	struct iio_dev *indio_dev;
>  	struct gyro_3d_state *gyro_state;
>  
> -	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*gyro_state));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*gyro_state));
>  	if (!indio_dev)
>  		return -ENOMEM;
>  	platform_set_drvdata(pdev, indio_dev);
> @@ -284,12 +285,10 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
>  						&gyro_state->common_attributes,
>  						gyro_3d_sensitivity_addresses,
>  						ARRAY_SIZE(gyro_3d_sensitivity_addresses));
> -	if (ret) {
> -		dev_err(&pdev->dev, "failed to setup common attributes\n");
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to setup common attributes\n");
>  
> -	indio_dev->channels = devm_kmemdup(&pdev->dev, gyro_3d_channels,
> +	indio_dev->channels = devm_kmemdup(dev, gyro_3d_channels,
>  					   sizeof(gyro_3d_channels), GFP_KERNEL);
This is the case I'm saying doesn't belong in this patch.

Jonathan

>  	if (!indio_dev->channels)
>  		return -ENOMEM;
> @@ -297,10 +296,8 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
>  	ret = gyro_3d_parse_report(pdev, hsdev,
>  				   (struct iio_chan_spec *)indio_dev->channels,
>  				   HID_USAGE_SENSOR_GYRO_3D, gyro_state);
> -	if (ret) {
> -		dev_err(&pdev->dev, "failed to setup attributes\n");
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to setup attributes\n");
>  
>  	indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
>  	indio_dev->info = &gyro_3d_info;
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.