From 051fb04712593a1bebdf638cd9f9935db2ce48aa Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Thu, 16 Oct 2014 06:35:24 -0500 Subject: [PATCH] greybus: don't assume subdevs are valid Most of the disconnect routines for the "subdevs" of a module blindly assume that initialization of the subdev was successful. Fix this by checking for null pointers. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/battery-gb.c | 2 ++ drivers/staging/greybus/gpio-gb.c | 2 ++ drivers/staging/greybus/i2c-gb.c | 2 ++ drivers/staging/greybus/sdio-gb.c | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/staging/greybus/battery-gb.c b/drivers/staging/greybus/battery-gb.c index 1ef2f17623b0..eaced9ab39d8 100644 --- a/drivers/staging/greybus/battery-gb.c +++ b/drivers/staging/greybus/battery-gb.c @@ -135,6 +135,8 @@ void gb_battery_disconnect(struct gb_module *gmod) struct gb_battery *gb; gb = gmod->gb_battery; + if (!gb) + return; power_supply_unregister(&gb->bat); diff --git a/drivers/staging/greybus/gpio-gb.c b/drivers/staging/greybus/gpio-gb.c index 2369175bf0f9..da20028e7c46 100644 --- a/drivers/staging/greybus/gpio-gb.c +++ b/drivers/staging/greybus/gpio-gb.c @@ -92,6 +92,8 @@ void gb_gpio_disconnect(struct gb_module *gmod) int retval; gb_gpio_dev = gmod->gb_gpio_dev; + if (!gb_gpio_dev) + return; retval = gpiochip_remove(&gb_gpio_dev->chip); kfree(gb_gpio_dev); diff --git a/drivers/staging/greybus/i2c-gb.c b/drivers/staging/greybus/i2c-gb.c index c01f41b59c55..0da195898ad4 100644 --- a/drivers/staging/greybus/i2c-gb.c +++ b/drivers/staging/greybus/i2c-gb.c @@ -121,6 +121,8 @@ void gb_i2c_disconnect(struct gb_module *gmod) struct gb_i2c_device *gb_i2c_dev; gb_i2c_dev = gmod->gb_i2c_dev; + if (!gb_i2c_dev) + return; i2c_del_adapter(gb_i2c_dev->adapter); kfree(gb_i2c_dev->adapter); kfree(gb_i2c_dev); diff --git a/drivers/staging/greybus/sdio-gb.c b/drivers/staging/greybus/sdio-gb.c index f7e80abcc0a0..239fcf773acb 100644 --- a/drivers/staging/greybus/sdio-gb.c +++ b/drivers/staging/greybus/sdio-gb.c @@ -71,8 +71,10 @@ void gb_sdio_disconnect(struct gb_module *gmod) struct gb_sdio_host *host; host = gmod->gb_sdio_host; - mmc = host->mmc; + if (!host) + return; + mmc = host->mmc; mmc_remove_host(mmc); mmc_free_host(mmc); } -- 2.39.5