From patchwork Tue Sep 18 00:53:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: axel lin X-Patchwork-Id: 1470111 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A5855400EB for ; Tue, 18 Sep 2012 00:53:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755865Ab2IRAxZ (ORCPT ); Mon, 17 Sep 2012 20:53:25 -0400 Received: from mail-oa0-f46.google.com ([209.85.219.46]:60609 "EHLO mail-oa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353Ab2IRAxY (ORCPT ); Mon, 17 Sep 2012 20:53:24 -0400 Received: by oago6 with SMTP id o6so5444039oag.19 for ; Mon, 17 Sep 2012 17:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:x-mailer:content-transfer-encoding:mime-version; bh=OQNr7WlR+W8kNuvMqMSuplYtMc3RQb5YnGOfMCq9sSc=; b=ckBXNOr0re0jgVL90GKqo3+ZDzb3kqxMVLauaz7KRPX0nDVZl+VAVHLlX3HGoI0pZr UcTt+Wj/c49pCP6xbOZguRLhng0lQ3WbAtagOjugNemc5dxBxuiB4bUF00nWhaFQCrWn o/gH6zH3lc1Fk1JAaAAEkVtB29UmR4b6dxOw1TKYclk3ZvAGl2D1WE8doxB0tzmaRb/9 /pBbv5XPjKIZVmIFu7607w/75Yum514F9wjSWBDhe4uRhc2/9Rum+BbljPghckP5Bs+O jg8Jj1G9f42E0XGNeIAkHFJwBWf9QtAnyg0YjHKt7aKnmdTlK9NFqGs9xaACh1DI18Py O/lA== Received: by 10.182.225.100 with SMTP id rj4mr13856407obc.64.1347929603573; Mon, 17 Sep 2012 17:53:23 -0700 (PDT) Received: from [114.39.107.123] (114-39-107-123.dynamic.hinet.net. [114.39.107.123]) by mx.google.com with ESMTPS id ig3sm12571193obb.0.2012.09.17.17.53.20 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Sep 2012 17:53:22 -0700 (PDT) Message-ID: <1347929598.6562.1.camel@phoenix> Subject: [PATCH v2 2/2] HID: hid-sensor-hub: Fix sensor_hub_probe error handling From: Axel Lin To: Jonathan Cameron Cc: Jiri Kosina , Srinivas Pandruvada , linux-input@vger.kernel.org Date: Tue, 18 Sep 2012 08:53:18 +0800 In-Reply-To: <1347929533.6562.0.camel@phoenix> References: <1347929533.6562.0.camel@phoenix> X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Fix below issues: 1. In the case of goto err_close, hid_hw_stop(hdev) is called twice. Fix it. 2. If fails to allocate MFD device name, we also need to free all successfully allocated names in previous iterations. 3. In sensor_hub_remove(), Call hid_hw_close() before hid_hw_stop(). 4. Adjust unnecessary change lines for hid_err. Signed-off-by: Axel Lin Acked-by: Jiri Kosina --- drivers/hid/hid-sensor-hub.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index 1faacf2..b9ce38e 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -564,8 +564,7 @@ static int sensor_hub_probe(struct hid_device *hdev, sizeof(struct mfd_cell), GFP_KERNEL); if (sd->hid_sensor_hub_client_devs == NULL) { - hid_err(hdev, - "Failed to allocate memory for mfd cells\n"); + hid_err(hdev, "Failed to allocate memory for mfd cells\n"); ret = -ENOMEM; goto err_close; } @@ -577,10 +576,9 @@ static int sensor_hub_probe(struct hid_device *hdev, name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x", field->physical); if (name == NULL) { - hid_err(hdev, - "Failed MFD device name\n"); + hid_err(hdev, "Failed MFD device name\n"); ret = -ENOMEM; - goto err_free_cells; + goto err_free_names; } sd->hid_sensor_hub_client_devs[ sd->hid_sensor_client_cnt].name = name; @@ -604,10 +602,8 @@ static int sensor_hub_probe(struct hid_device *hdev, err_free_names: for (i = 0; i < sd->hid_sensor_client_cnt ; ++i) kfree(sd->hid_sensor_hub_client_devs[i].name); -err_free_cells: kfree(sd->hid_sensor_hub_client_devs); err_close: - hid_hw_stop(hdev); hid_hw_close(hdev); err_stop_hw: hid_hw_stop(hdev); @@ -626,8 +622,8 @@ static void sensor_hub_remove(struct hid_device *hdev) int i; hid_dbg(hdev, " hardware removed\n"); - hid_hw_stop(hdev); hid_hw_close(hdev); + hid_hw_stop(hdev); spin_lock_irqsave(&data->lock, flags); if (data->pending.status) complete(&data->pending.ready);