* [PATCH] eeprom: at24: code shrink
@ 2017-12-10 19:29 Bartosz Golaszewski
2017-12-11 8:08 ` Uwe Kleine-König
2017-12-18 17:45 ` Bartosz Golaszewski
0 siblings, 2 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2017-12-10 19:29 UTC (permalink / raw)
To: Heiner Kallweit, linux-i2c; +Cc: linux-kernel, Bartosz Golaszewski
A regmap_config struct is pretty big and declaring two of them
statically just to tweak the reg_bits value adds unnecessary bloat.
Declare the regmap config locally in at24_probe() instead.
Bloat-o-meter output:
add/remove: 0/2 grow/shrink: 1/0 up/down: 20/-272 (-252)
Function old new delta
at24_probe 1564 1584 +20
regmap_config_8 136 - -136
regmap_config_16 136 - -136
Total: Before=7010, After=6758, chg -3.59%
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
drivers/misc/eeprom/at24.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index ded86474b3de..5ecddbc74732 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -518,20 +518,6 @@ static void at24_regmap_lock_unlock_none(void *map)
}
-static const struct regmap_config regmap_config_8 = {
- .reg_bits = 8,
- .val_bits = 8,
- .lock = at24_regmap_lock_unlock_none,
- .unlock = at24_regmap_lock_unlock_none,
-};
-
-static const struct regmap_config regmap_config_16 = {
- .reg_bits = 16,
- .val_bits = 8,
- .lock = at24_regmap_lock_unlock_none,
- .unlock = at24_regmap_lock_unlock_none,
-};
-
static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct at24_platform_data chip;
@@ -540,7 +526,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
struct at24_data *at24;
int err;
unsigned i, num_addresses;
- const struct regmap_config *config;
+ struct regmap_config config = { };
u8 test_byte;
if (client->dev.platform_data) {
@@ -609,10 +595,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
num_addresses = DIV_ROUND_UP(chip.byte_len,
(chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
- if (chip.flags & AT24_FLAG_ADDR16)
- config = ®map_config_16;
- else
- config = ®map_config_8;
+ config.val_bits = 8;
+ config.lock = config.unlock = at24_regmap_lock_unlock_none;
+ config.reg_bits = (chip.flags & AT24_FLAG_ADDR16) ? 16 : 8;
at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) +
num_addresses * sizeof(struct at24_client), GFP_KERNEL);
@@ -625,7 +610,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->offset_adj = at24_get_offset_adj(chip.flags, chip.byte_len);
at24->client[0].client = client;
- at24->client[0].regmap = devm_regmap_init_i2c(client, config);
+ at24->client[0].regmap = devm_regmap_init_i2c(client, &config);
if (IS_ERR(at24->client[0].regmap))
return PTR_ERR(at24->client[0].regmap);
@@ -654,7 +639,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
goto err_clients;
}
at24->client[i].regmap = devm_regmap_init_i2c(
- at24->client[i].client, config);
+ at24->client[i].client, &config);
if (IS_ERR(at24->client[i].regmap)) {
err = PTR_ERR(at24->client[i].regmap);
goto err_clients;
--
2.15.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] eeprom: at24: code shrink
2017-12-10 19:29 [PATCH] eeprom: at24: code shrink Bartosz Golaszewski
@ 2017-12-11 8:08 ` Uwe Kleine-König
2017-12-11 9:38 ` Bartosz Golaszewski
2017-12-18 17:45 ` Bartosz Golaszewski
1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2017-12-11 8:08 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: Heiner Kallweit, linux-i2c, linux-kernel
Hello,
On Sun, Dec 10, 2017 at 08:29:47PM +0100, Bartosz Golaszewski wrote:
> @@ -625,7 +610,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> at24->offset_adj = at24_get_offset_adj(chip.flags, chip.byte_len);
>
> at24->client[0].client = client;
> - at24->client[0].regmap = devm_regmap_init_i2c(client, config);
> + at24->client[0].regmap = devm_regmap_init_i2c(client, &config);
> if (IS_ERR(at24->client[0].regmap))
> return PTR_ERR(at24->client[0].regmap);
>
One side effect here that the lockdep name changes from (unhelpful)
"config" to (unhelpful and ugly) "&config". Probably doesn't matter much
...
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] eeprom: at24: code shrink
2017-12-11 8:08 ` Uwe Kleine-König
@ 2017-12-11 9:38 ` Bartosz Golaszewski
0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2017-12-11 9:38 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Heiner Kallweit, linux-i2c, Linux Kernel Mailing List
2017-12-11 9:08 GMT+01:00 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hello,
>
> On Sun, Dec 10, 2017 at 08:29:47PM +0100, Bartosz Golaszewski wrote:
>> @@ -625,7 +610,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>> at24->offset_adj = at24_get_offset_adj(chip.flags, chip.byte_len);
>>
>> at24->client[0].client = client;
>> - at24->client[0].regmap = devm_regmap_init_i2c(client, config);
>> + at24->client[0].regmap = devm_regmap_init_i2c(client, &config);
>> if (IS_ERR(at24->client[0].regmap))
>> return PTR_ERR(at24->client[0].regmap);
>>
>
> One side effect here that the lockdep name changes from (unhelpful)
> "config" to (unhelpful and ugly) "&config". Probably doesn't matter much
> ...
>
> Best regards
> Uwe
>
We can always rename the variable to regmap_config or smth, but in
case of a lockdep splat we'll see the stack trace anyway.
Thanks,
Bartosz
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] eeprom: at24: code shrink
2017-12-10 19:29 [PATCH] eeprom: at24: code shrink Bartosz Golaszewski
2017-12-11 8:08 ` Uwe Kleine-König
@ 2017-12-18 17:45 ` Bartosz Golaszewski
1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2017-12-18 17:45 UTC (permalink / raw)
To: linux-i2c; +Cc: Linux Kernel Mailing List, Bartosz Golaszewski
2017-12-10 20:29 GMT+01:00 Bartosz Golaszewski <brgl@bgdev.pl>:
> A regmap_config struct is pretty big and declaring two of them
> statically just to tweak the reg_bits value adds unnecessary bloat.
>
> Declare the regmap config locally in at24_probe() instead.
>
> Bloat-o-meter output:
>
> add/remove: 0/2 grow/shrink: 1/0 up/down: 20/-272 (-252)
> Function old new delta
> at24_probe 1564 1584 +20
> regmap_config_8 136 - -136
> regmap_config_16 136 - -136
> Total: Before=7010, After=6758, chg -3.59%
>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
> drivers/misc/eeprom/at24.c | 27 ++++++---------------------
> 1 file changed, 6 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index ded86474b3de..5ecddbc74732 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -518,20 +518,6 @@ static void at24_regmap_lock_unlock_none(void *map)
>
> }
>
> -static const struct regmap_config regmap_config_8 = {
> - .reg_bits = 8,
> - .val_bits = 8,
> - .lock = at24_regmap_lock_unlock_none,
> - .unlock = at24_regmap_lock_unlock_none,
> -};
> -
> -static const struct regmap_config regmap_config_16 = {
> - .reg_bits = 16,
> - .val_bits = 8,
> - .lock = at24_regmap_lock_unlock_none,
> - .unlock = at24_regmap_lock_unlock_none,
> -};
> -
> static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> {
> struct at24_platform_data chip;
> @@ -540,7 +526,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> struct at24_data *at24;
> int err;
> unsigned i, num_addresses;
> - const struct regmap_config *config;
> + struct regmap_config config = { };
> u8 test_byte;
>
> if (client->dev.platform_data) {
> @@ -609,10 +595,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> num_addresses = DIV_ROUND_UP(chip.byte_len,
> (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
>
> - if (chip.flags & AT24_FLAG_ADDR16)
> - config = ®map_config_16;
> - else
> - config = ®map_config_8;
> + config.val_bits = 8;
> + config.lock = config.unlock = at24_regmap_lock_unlock_none;
> + config.reg_bits = (chip.flags & AT24_FLAG_ADDR16) ? 16 : 8;
>
> at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) +
> num_addresses * sizeof(struct at24_client), GFP_KERNEL);
> @@ -625,7 +610,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> at24->offset_adj = at24_get_offset_adj(chip.flags, chip.byte_len);
>
> at24->client[0].client = client;
> - at24->client[0].regmap = devm_regmap_init_i2c(client, config);
> + at24->client[0].regmap = devm_regmap_init_i2c(client, &config);
> if (IS_ERR(at24->client[0].regmap))
> return PTR_ERR(at24->client[0].regmap);
>
> @@ -654,7 +639,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> goto err_clients;
> }
> at24->client[i].regmap = devm_regmap_init_i2c(
> - at24->client[i].client, config);
> + at24->client[i].client, &config);
> if (IS_ERR(at24->client[i].regmap)) {
> err = PTR_ERR(at24->client[i].regmap);
> goto err_clients;
> --
> 2.15.1
>
There were no more comments, so patch applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-12-18 17:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-10 19:29 [PATCH] eeprom: at24: code shrink Bartosz Golaszewski
2017-12-11 8:08 ` Uwe Kleine-König
2017-12-11 9:38 ` Bartosz Golaszewski
2017-12-18 17:45 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox