From patchwork Tue Jul 12 08:03:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 967512 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 p6C8CMMa015567 for ; Tue, 12 Jul 2011 08:12:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751547Ab1GLIEB (ORCPT ); Tue, 12 Jul 2011 04:04:01 -0400 Received: from mtagate6.uk.ibm.com ([194.196.100.166]:48012 "EHLO mtagate6.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751476Ab1GLIDy (ORCPT ); Tue, 12 Jul 2011 04:03:54 -0400 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate6.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p6C83cFh028532; Tue, 12 Jul 2011 08:03:39 GMT Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6C83coE2531352; Tue, 12 Jul 2011 09:03:38 +0100 Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6C83aGe023722; Tue, 12 Jul 2011 09:03:37 +0100 Received: from stefanha-thinkpad.manchester-maybrook.uk.ibm.com (dyn-9-174-219-30.manchester-maybrook.uk.ibm.com [9.174.219.30]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p6C83ZAh023704; Tue, 12 Jul 2011 09:03:36 +0100 From: Stefan Hajnoczi To: Len Brown , Anton Vorontsov , David Woodhouse Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Hajnoczi Subject: [PATCH 1/3] power_supply: scrub device pointer if registration fails Date: Tue, 12 Jul 2011 09:03:27 +0100 Message-Id: <1310457809-2731-2-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1310457809-2731-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1310457809-2731-1-git-send-email-stefanha@linux.vnet.ibm.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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]); Tue, 12 Jul 2011 08:12:24 +0000 (UTC) This patch makes power_supply_register() safer for callers that are not being careful. When the function fails it leaves the caller's psy.dev pointer set to the stale power supply device. A correct caller would handle the error return and never use psy.dev but the example of drivers/acpi/battery.c shows otherwise. Clear the psy.dev pointer when power_supply_register() fails so the caller either sees a valid pointer on success or NULL on failure. Signed-off-by: Stefan Hajnoczi --- drivers/power/power_supply_core.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 329b46b..33d4068 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c @@ -194,6 +194,7 @@ create_triggers_failed: kobject_set_name_failed: device_add_failed: put_device(dev); + psy->dev = NULL; /* make it crystal-clear that we failed */ success: return rc; }