From patchwork Mon Sep 5 16:45:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 1125062 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p85GjkNH024501 for ; Mon, 5 Sep 2011 16:45:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751624Ab1IEQpq (ORCPT ); Mon, 5 Sep 2011 12:45:46 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:48710 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751605Ab1IEQpp (ORCPT ); Mon, 5 Sep 2011 12:45:45 -0400 Received: by ewy4 with SMTP id 4so2295924ewy.19 for ; Mon, 05 Sep 2011 09:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=q/X9fABOhlZfCu/ljpwaTmD7XWjJjAkyRYlnYWN72x4=; b=WCFsTs1FJRehWJDdp7+b7vPgcEacAleD50kzQcItdckn6Ddjia7URbhNpk+alZD7Sj KLa1/824oR3Tvh8wBAv3mHBr0WhdRcxBlDTYSiwPRE9fmw6/XqGSAsHPsWz6vSspTvDL tyoeo7lZorZDM8Ya3+Q8UVbJFAB58ZykoK9sE= Received: by 10.213.26.4 with SMTP id b4mr613419ebc.103.1315241144425; Mon, 05 Sep 2011 09:45:44 -0700 (PDT) Received: from localhost.localdomain (stgt-5f70b1cc.pool.mediaWays.net [95.112.177.204]) by mx.google.com with ESMTPS id e4sm10673822eec.10.2011.09.05.09.45.42 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Sep 2011 09:45:43 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, David Herrmann Subject: [PATCH 1/2] HID: wacom: Fix error path of power-supply initialization Date: Mon, 5 Sep 2011 18:45:28 +0200 Message-Id: <1315241129-3889-1-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.6.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 05 Sep 2011 16:45:48 +0000 (UTC) power_supply_unregister() must not be called if power_supply_register() failed. The wdata->psy.dev pointer may point to invalid memory after a failed power_supply_register() and hence wacom_remove() will fail while calling power_supply_unregister(). This changes the wacom_probe function to fail if it cannot register the power_supply devices. If we would want to keep the previous behaviour we had to keep some flag about the power_supply state and check it on wacom_remove, but this seems inappropriate here. Hence, we simply fail, too, if power_supply_register fails. Signed-off-by: David Herrmann --- drivers/hid/hid-wacom.c | 21 +++++++++------------ 1 files changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index 0688832..f66a597 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c @@ -353,11 +353,7 @@ static int wacom_probe(struct hid_device *hdev, if (ret) { hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n", ret); - /* - * battery attribute is not critical for the tablet, but if it - * failed then there is no need to create ac attribute - */ - goto move_on; + goto err_battery; } wdata->ac.properties = wacom_ac_props; @@ -371,14 +367,8 @@ static int wacom_probe(struct hid_device *hdev, if (ret) { hid_warn(hdev, "can't create ac battery attribute, err: %d\n", ret); - /* - * ac attribute is not critical for the tablet, but if it - * failed then we don't want to battery attribute to exist - */ - power_supply_unregister(&wdata->battery); + goto err_ac; } - -move_on: #endif hidinput = list_entry(hdev->inputs.next, struct hid_input, list); input = hidinput->input; @@ -416,6 +406,13 @@ move_on: return 0; +#ifdef CONFIG_HID_WACOM_POWER_SUPPLY +err_ac: + power_supply_unregister(&wdata->battery); +err_battery: + device_remove_file(&hdev->dev, &dev_attr_speed); + hid_hw_stop(hdev); +#endif err_free: kfree(wdata); return ret;