From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: Len Brown <lenb@kernel.org>, Anton Vorontsov <cbou@mail.ru>,
David Woodhouse <dwmw2@infradead.org>
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [PATCH 1/3] power_supply: scrub device pointer if registration fails
Date: Tue, 12 Jul 2011 09:03:27 +0100 [thread overview]
Message-ID: <1310457809-2731-2-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1310457809-2731-1-git-send-email-stefanha@linux.vnet.ibm.com>
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 <stefanha@linux.vnet.ibm.com>
---
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;
}
--
1.7.5.4
next prev parent reply other threads:[~2011-07-12 8:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-12 8:03 [PATCH 0/3] ACPI / Battery: fix NULL pointer dereference from battery Stefan Hajnoczi
2011-07-12 8:03 ` Stefan Hajnoczi
2011-07-12 8:03 ` Stefan Hajnoczi [this message]
2011-07-12 15:09 ` [PATCH 1/3] power_supply: scrub device pointer if registration fails Anton Vorontsov
2011-07-12 15:30 ` Stefan Hajnoczi
2011-07-12 17:23 ` Anton Vorontsov
2011-07-14 6:07 ` Stefan Hajnoczi
2011-07-12 8:03 ` [PATCH 2/3] ACPI / Battery: avoid acpi_battery_add() use-after-free Stefan Hajnoczi
2011-07-16 22:56 ` Len Brown
2011-07-12 8:03 ` [PATCH 3/3] ACPI / Battery: propagate sysfs error in acpi_battery_add() Stefan Hajnoczi
2011-07-16 22:58 ` Len Brown
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=1310457809-2731-2-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=cbou@mail.ru \
--cc=dwmw2@infradead.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.