diff options
author | Phil Reid <preid@electromag.com.au> | 2016-09-19 21:01:12 -0400 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2016-09-20 20:04:47 -0400 |
commit | 389958bb6be8b08c9f6d350dcaa9fc127123eada (patch) | |
tree | d2cbb8cd4aa37f7b2cd803da42bef8936ee67d8d | |
parent | bb1e41ba324fe4bb71be3ef8d0eda29f0ba44ffa (diff) |
power: supply: sbs-battery: Cleanup removal of chip->pdata
There where still a few lingering references to pdata after commit
power: supply: sbs-battery: simplify DT parsing.
Remove pdata from struct·sbs_info and conditional checks to ser if this
was set from the i2c read / write functions.
Instead of call max in each function for incrementing poll_retry_count
do it once in the probe function.
Fixup null pointer dereference in to pdata in sbs_external_power_changed.
Change retry counts to u32 to avoid need for max.
Signed-off-by: Phil Reid <preid@electromag.com.au>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r-- | drivers/power/supply/sbs-battery.c | 22 | ||||
-rw-r--r-- | include/linux/power/sbs-battery.h | 4 |
2 files changed, 11 insertions, 15 deletions
diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index bc7acdf84d60..8bb2eb38eb1c 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c | |||
@@ -163,14 +163,13 @@ static enum power_supply_property sbs_properties[] = { | |||
163 | struct sbs_info { | 163 | struct sbs_info { |
164 | struct i2c_client *client; | 164 | struct i2c_client *client; |
165 | struct power_supply *power_supply; | 165 | struct power_supply *power_supply; |
166 | struct sbs_platform_data *pdata; | ||
167 | bool is_present; | 166 | bool is_present; |
168 | struct gpio_desc *gpio_detect; | 167 | struct gpio_desc *gpio_detect; |
169 | bool enable_detection; | 168 | bool enable_detection; |
170 | int last_state; | 169 | int last_state; |
171 | int poll_time; | 170 | int poll_time; |
172 | int i2c_retry_count; | 171 | u32 i2c_retry_count; |
173 | int poll_retry_count; | 172 | u32 poll_retry_count; |
174 | struct delayed_work work; | 173 | struct delayed_work work; |
175 | int ignore_changes; | 174 | int ignore_changes; |
176 | }; | 175 | }; |
@@ -185,8 +184,7 @@ static int sbs_read_word_data(struct i2c_client *client, u8 address) | |||
185 | s32 ret = 0; | 184 | s32 ret = 0; |
186 | int retries = 1; | 185 | int retries = 1; |
187 | 186 | ||
188 | if (chip->pdata) | 187 | retries = chip->i2c_retry_count; |
189 | retries = max(chip->i2c_retry_count + 1, 1); | ||
190 | 188 | ||
191 | while (retries > 0) { | 189 | while (retries > 0) { |
192 | ret = i2c_smbus_read_word_data(client, address); | 190 | ret = i2c_smbus_read_word_data(client, address); |
@@ -213,10 +211,8 @@ static int sbs_read_string_data(struct i2c_client *client, u8 address, | |||
213 | int retries_length = 1, retries_block = 1; | 211 | int retries_length = 1, retries_block = 1; |
214 | u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; | 212 | u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; |
215 | 213 | ||
216 | if (chip->pdata) { | 214 | retries_length = chip->i2c_retry_count; |
217 | retries_length = max(chip->i2c_retry_count + 1, 1); | 215 | retries_block = chip->i2c_retry_count; |
218 | retries_block = max(chip->i2c_retry_count + 1, 1); | ||
219 | } | ||
220 | 216 | ||
221 | /* Adapter needs to support these two functions */ | 217 | /* Adapter needs to support these two functions */ |
222 | if (!i2c_check_functionality(client->adapter, | 218 | if (!i2c_check_functionality(client->adapter, |
@@ -280,8 +276,7 @@ static int sbs_write_word_data(struct i2c_client *client, u8 address, | |||
280 | s32 ret = 0; | 276 | s32 ret = 0; |
281 | int retries = 1; | 277 | int retries = 1; |
282 | 278 | ||
283 | if (chip->pdata) | 279 | retries = chip->i2c_retry_count; |
284 | retries = max(chip->i2c_retry_count + 1, 1); | ||
285 | 280 | ||
286 | while (retries > 0) { | 281 | while (retries > 0) { |
287 | ret = i2c_smbus_write_word_data(client, address, | 282 | ret = i2c_smbus_write_word_data(client, address, |
@@ -708,7 +703,7 @@ static void sbs_external_power_changed(struct power_supply *psy) | |||
708 | cancel_delayed_work_sync(&chip->work); | 703 | cancel_delayed_work_sync(&chip->work); |
709 | 704 | ||
710 | schedule_delayed_work(&chip->work, HZ); | 705 | schedule_delayed_work(&chip->work, HZ); |
711 | chip->poll_time = chip->pdata->poll_retry_count; | 706 | chip->poll_time = chip->poll_retry_count; |
712 | } | 707 | } |
713 | 708 | ||
714 | static void sbs_delayed_work(struct work_struct *work) | 709 | static void sbs_delayed_work(struct work_struct *work) |
@@ -792,7 +787,7 @@ static int sbs_probe(struct i2c_client *client, | |||
792 | rc = of_property_read_u32(client->dev.of_node, "sbs,i2c-retry-count", | 787 | rc = of_property_read_u32(client->dev.of_node, "sbs,i2c-retry-count", |
793 | &chip->i2c_retry_count); | 788 | &chip->i2c_retry_count); |
794 | if (rc) | 789 | if (rc) |
795 | chip->i2c_retry_count = 1; | 790 | chip->i2c_retry_count = 0; |
796 | 791 | ||
797 | rc = of_property_read_u32(client->dev.of_node, "sbs,poll-retry-count", | 792 | rc = of_property_read_u32(client->dev.of_node, "sbs,poll-retry-count", |
798 | &chip->poll_retry_count); | 793 | &chip->poll_retry_count); |
@@ -803,6 +798,7 @@ static int sbs_probe(struct i2c_client *client, | |||
803 | chip->poll_retry_count = pdata->poll_retry_count; | 798 | chip->poll_retry_count = pdata->poll_retry_count; |
804 | chip->i2c_retry_count = pdata->i2c_retry_count; | 799 | chip->i2c_retry_count = pdata->i2c_retry_count; |
805 | } | 800 | } |
801 | chip->i2c_retry_count = chip->i2c_retry_count + 1; | ||
806 | 802 | ||
807 | chip->gpio_detect = devm_gpiod_get_optional(&client->dev, | 803 | chip->gpio_detect = devm_gpiod_get_optional(&client->dev, |
808 | "sbs,battery-detect", GPIOD_IN); | 804 | "sbs,battery-detect", GPIOD_IN); |
diff --git a/include/linux/power/sbs-battery.h b/include/linux/power/sbs-battery.h index 811f1a0c00cb..519b8b43239a 100644 --- a/include/linux/power/sbs-battery.h +++ b/include/linux/power/sbs-battery.h | |||
@@ -31,8 +31,8 @@ | |||
31 | * external change notification | 31 | * external change notification |
32 | */ | 32 | */ |
33 | struct sbs_platform_data { | 33 | struct sbs_platform_data { |
34 | int i2c_retry_count; | 34 | u32 i2c_retry_count; |
35 | int poll_retry_count; | 35 | u32 poll_retry_count; |
36 | }; | 36 | }; |
37 | 37 | ||
38 | #endif | 38 | #endif |