[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git-commits-head
Subject:    hwmon: (max1111) Return -ENODEV from max1111_read_channel if not instantiated
From:       "Linux Kernel Mailing List" <linux-kernel () vger ! kernel ! org>
Date:       2016-03-30 18:31:30
Message-ID: 20160330183130.6356E660E09 () gitolite ! kernel ! org
[Download RAW message or body]

Web:        https://git.kernel.org/torvalds/c/3c2e2266a5bd2d1cef258e6e54dca1d99946379f
Commit:     3c2e2266a5bd2d1cef258e6e54dca1d99946379f
Parent:     f55532a0c0b8bb6148f4e07853b876ef73bc69ca
Refname:    refs/heads/master
Author:     Guenter Roeck <linux@roeck-us.net>
AuthorDate: Sat Mar 26 12:28:05 2016 -0700
Committer:  Guenter Roeck <linux@roeck-us.net>
CommitDate: Sun Mar 27 10:37:48 2016 -0700

    hwmon: (max1111) Return -ENODEV from max1111_read_channel if not instantiated
    
    arm:pxa_defconfig can result in the following crash if the max1111 driver
    is not instantiated.
    
    Unhandled fault: page domain fault (0x01b) at 0x00000000
    pgd = c0004000
    [00000000] *pgd=00000000
    Internal error: : 1b [#1] PREEMPT ARM
    Modules linked in:
    CPU: 0 PID: 300 Comm: kworker/0:1 Not tainted 4.5.0-01301-g1701f680407c #10
    Hardware name: SHARP Akita
    Workqueue: events sharpsl_charge_toggle
    task: c390a000 ti: c391e000 task.ti: c391e000
    PC is at max1111_read_channel+0x20/0x30
    LR is at sharpsl_pm_pxa_read_max1111+0x2c/0x3c
    pc : [<c03aaab0>]    lr : [<c0024b50>]    psr: 20000013
    ...
    [<c03aaab0>] (max1111_read_channel) from [<c0024b50>]
    					(sharpsl_pm_pxa_read_max1111+0x2c/0x3c)
    [<c0024b50>] (sharpsl_pm_pxa_read_max1111) from [<c00262e0>]
    					(spitzpm_read_devdata+0x5c/0xc4)
    [<c00262e0>] (spitzpm_read_devdata) from [<c0024094>]
    					(sharpsl_check_battery_temp+0x78/0x110)
    [<c0024094>] (sharpsl_check_battery_temp) from [<c0024f9c>]
    					(sharpsl_charge_toggle+0x48/0x110)
    [<c0024f9c>] (sharpsl_charge_toggle) from [<c004429c>]
    					(process_one_work+0x14c/0x48c)
    [<c004429c>] (process_one_work) from [<c0044618>] (worker_thread+0x3c/0x5d4)
    [<c0044618>] (worker_thread) from [<c004a238>] (kthread+0xd0/0xec)
    [<c004a238>] (kthread) from [<c000a670>] (ret_from_fork+0x14/0x24)
    
    This can occur because the SPI controller driver (SPI_PXA2XX) is built as
    module and thus not necessarily loaded. While building SPI_PXA2XX into the
    kernel would make the problem disappear, it appears prudent to ensure that
    the driver is instantiated before accessing its data structures.
    
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: stable@vger.kernel.org
    Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/max1111.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index 36544c4..303d0c9 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -85,6 +85,9 @@ static struct max1111_data *the_max1111;
 
 int max1111_read_channel(int channel)
 {
+	if (!the_max1111 || !the_max1111->spi)
+		return -ENODEV;
+
 	return max1111_read(&the_max1111->spi->dev, channel);
 }
 EXPORT_SYMBOL(max1111_read_channel);
@@ -258,6 +261,9 @@ static int max1111_remove(struct spi_device *spi)
 {
 	struct max1111_data *data = spi_get_drvdata(spi);
 
+#ifdef CONFIG_SHARPSL_PM
+	the_max1111 = NULL;
+#endif
 	hwmon_device_unregister(data->hwmon_dev);
 	sysfs_remove_group(&spi->dev.kobj, &max1110_attr_group);
 	sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic