Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Phil Reid and committed by
Sebastian Reichel
389958bb bb1e41ba

+11 -15
+9 -13
drivers/power/supply/sbs-battery.c
··· 163 163 struct sbs_info { 164 164 struct i2c_client *client; 165 165 struct power_supply *power_supply; 166 - struct sbs_platform_data *pdata; 167 166 bool is_present; 168 167 struct gpio_desc *gpio_detect; 169 168 bool enable_detection; 170 169 int last_state; 171 170 int poll_time; 172 - int i2c_retry_count; 173 - int poll_retry_count; 171 + u32 i2c_retry_count; 172 + u32 poll_retry_count; 174 173 struct delayed_work work; 175 174 int ignore_changes; 176 175 }; ··· 184 185 s32 ret = 0; 185 186 int retries = 1; 186 187 187 - if (chip->pdata) 188 - retries = max(chip->i2c_retry_count + 1, 1); 188 + retries = chip->i2c_retry_count; 189 189 190 190 while (retries > 0) { 191 191 ret = i2c_smbus_read_word_data(client, address); ··· 211 213 int retries_length = 1, retries_block = 1; 212 214 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; 213 215 214 - if (chip->pdata) { 215 - retries_length = max(chip->i2c_retry_count + 1, 1); 216 - retries_block = max(chip->i2c_retry_count + 1, 1); 217 - } 216 + retries_length = chip->i2c_retry_count; 217 + retries_block = chip->i2c_retry_count; 218 218 219 219 /* Adapter needs to support these two functions */ 220 220 if (!i2c_check_functionality(client->adapter, ··· 276 280 s32 ret = 0; 277 281 int retries = 1; 278 282 279 - if (chip->pdata) 280 - retries = max(chip->i2c_retry_count + 1, 1); 283 + retries = chip->i2c_retry_count; 281 284 282 285 while (retries > 0) { 283 286 ret = i2c_smbus_write_word_data(client, address, ··· 703 708 cancel_delayed_work_sync(&chip->work); 704 709 705 710 schedule_delayed_work(&chip->work, HZ); 706 - chip->poll_time = chip->pdata->poll_retry_count; 711 + chip->poll_time = chip->poll_retry_count; 707 712 } 708 713 709 714 static void sbs_delayed_work(struct work_struct *work) ··· 787 792 rc = of_property_read_u32(client->dev.of_node, "sbs,i2c-retry-count", 788 793 &chip->i2c_retry_count); 789 794 if (rc) 790 - chip->i2c_retry_count = 1; 795 + chip->i2c_retry_count = 0; 791 796 792 797 rc = of_property_read_u32(client->dev.of_node, "sbs,poll-retry-count", 793 798 &chip->poll_retry_count); ··· 798 803 chip->poll_retry_count = pdata->poll_retry_count; 799 804 chip->i2c_retry_count = pdata->i2c_retry_count; 800 805 } 806 + chip->i2c_retry_count = chip->i2c_retry_count + 1; 801 807 802 808 chip->gpio_detect = devm_gpiod_get_optional(&client->dev, 803 809 "sbs,battery-detect", GPIOD_IN);
+2 -2
include/linux/power/sbs-battery.h
··· 31 31 * external change notification 32 32 */ 33 33 struct sbs_platform_data { 34 - int i2c_retry_count; 35 - int poll_retry_count; 34 + u32 i2c_retry_count; 35 + u32 poll_retry_count; 36 36 }; 37 37 38 38 #endif