From patchwork Wed Aug 14 08:07:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 2844224 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D74719F239 for ; Wed, 14 Aug 2013 08:07:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EC42202D1 for ; Wed, 14 Aug 2013 08:07:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D790E202EA for ; Wed, 14 Aug 2013 08:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754917Ab3HNIHd (ORCPT ); Wed, 14 Aug 2013 04:07:33 -0400 Received: from mga14.intel.com ([143.182.124.37]:17884 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756769Ab3HNIHa (ORCPT ); Wed, 14 Aug 2013 04:07:30 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 14 Aug 2013 01:07:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.89,875,1367996400"; d="scan'208";a="346120543" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.173]) by azsmga001.ch.intel.com with ESMTP; 14 Aug 2013 01:07:23 -0700 Received: from andy by smile with local (Exim 4.80) (envelope-from ) id 1V9W6q-0005RJ-U2; Wed, 14 Aug 2013 11:07:12 +0300 From: Andy Shevchenko To: Jiri Kosina , linux-input@vger.kernel.org, Srinivas Pandruvada Cc: Andy Shevchenko Subject: [PATCH 3/4] hid-sensor-hub: move to devm_kzalloc Date: Wed, 14 Aug 2013 11:07:10 +0300 Message-Id: <1376467631-20857-3-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 1.8.4.rc2 In-Reply-To: <1376467631-20857-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1376467631-20857-1-git-send-email-andriy.shevchenko@linux.intel.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP devm_kzalloc() will manage resources freeing and allows to make error path smaller and nicer. Signed-off-by: Andy Shevchenko --- 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[] = {