linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jiri Kosina <jkosina@suse.cz>,
	linux-input@vger.kernel.org,
	Srinivas Pandruvada <srinivas.pandruvada@intel.com>
Subject: Re: [PATCH 3/4] hid-sensor-hub: move to devm_kzalloc
Date: Mon, 19 Aug 2013 08:31:08 -0700	[thread overview]
Message-ID: <52123A3C.6010404@linux.intel.com> (raw)
In-Reply-To: <1376467631-20857-3-git-send-email-andriy.shevchenko@linux.intel.com>

On 08/14/2013 01:07 AM, Andy Shevchenko wrote:
> devm_kzalloc() will manage resources freeing and allows to make error path
> smaller and nicer.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/hid/hid-sensor-hub.c | 17 +++++------------
>   1 file changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
> index d0687d0..4cb19df 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -477,16 +477,15 @@ static int sensor_hub_probe(struct hid_device *hdev,
>   	struct hid_field *field;
>   	int dev_cnt;
>   
> -	sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL);
> +	sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL);
>   	if (!sd) {
>   		hid_err(hdev, "cannot allocate Sensor data\n");
>   		return -ENOMEM;
>   	}
> -	sd->hsdev = kzalloc(sizeof(struct hid_sensor_hub_device), GFP_KERNEL);
> +	sd->hsdev = devm_kzalloc(&hdev->dev, sizeof(*sd->hsdev), GFP_KERNEL);
>   	if (!sd->hsdev) {
>   		hid_err(hdev, "cannot allocate hid_sensor_hub_device\n");
> -		ret = -ENOMEM;
> -		goto err_free_hub;
> +		return -ENOMEM;
>   	}
>   	hid_set_drvdata(hdev, sd);
>   	sd->hsdev->hdev = hdev;
> @@ -498,14 +497,14 @@ static int sensor_hub_probe(struct hid_device *hdev,
>   	ret = hid_parse(hdev);
>   	if (ret) {
>   		hid_err(hdev, "parse failed\n");
> -		goto err_free;
> +		return ret;
>   	}
>   	INIT_LIST_HEAD(&hdev->inputs);
>   
>   	ret = hid_hw_start(hdev, 0);
>   	if (ret) {
>   		hid_err(hdev, "hw start failed\n");
> -		goto err_free;
> +		return ret;
>   	}
>   	ret = hid_hw_open(hdev);
>   	if (ret) {
> @@ -570,10 +569,6 @@ err_close:
>   	hid_hw_close(hdev);
>   err_stop_hw:
>   	hid_hw_stop(hdev);
> -err_free:
> -	kfree(sd->hsdev);
> -err_free_hub:
> -	kfree(sd);
>   
>   	return ret;
>   }
> @@ -597,8 +592,6 @@ static void sensor_hub_remove(struct hid_device *hdev)
>   	kfree(data->hid_sensor_hub_client_devs);
>   	hid_set_drvdata(hdev, NULL);
>   	mutex_destroy(&data->mutex);
> -	kfree(data->hsdev);
> -	kfree(data);
>   }
>   
>   static const struct hid_device_id sensor_hub_devices[] = {
Agreed.

Thanks,
Srinivas

  reply	other threads:[~2013-08-19 15:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14  8:07 [PATCH 1/4] hid-sensor-hub: fix style of comments Andy Shevchenko
2013-08-14  8:07 ` [PATCH 2/4] hid-sensor-hub: fix indentation accross the code Andy Shevchenko
2013-08-19 15:28   ` Srinivas Pandruvada
2013-08-29 14:53     ` Andy Shevchenko
2013-09-04 10:21       ` Jiri Kosina
2013-08-14  8:07 ` [PATCH 3/4] hid-sensor-hub: move to devm_kzalloc Andy Shevchenko
2013-08-19 15:31   ` Srinivas Pandruvada [this message]
2013-08-14  8:07 ` [PATCH 4/4] hid-sensor-hub: change kmalloc + memcpy by kmemdup Andy Shevchenko
2013-08-19 15:32   ` Srinivas Pandruvada
2013-08-19  8:48 ` [PATCH 1/4] hid-sensor-hub: fix style of comments Andy Shevchenko
2013-08-19 15:26   ` Srinivas Pandruvada
2013-08-26 11:46 ` Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52123A3C.6010404@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=srinivas.pandruvada@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).