Skip to content

Commit

Permalink
i2c: core: Allocate temporary client dynamically
Browse files Browse the repository at this point in the history
drivers/i2c/i2c-core-base.c: In function ‘i2c_detect.isra’:
drivers/i2c/i2c-core-base.c:2544:1: warning: the frame size of 1312 bytes is larger than 1024 bytes [-Wframe-larger-than=]
 2544 | }
      | ^

Fix this by allocating the temporary client structure dynamically, as it
is a rather large structure (1216 bytes, depending on kernel config).
This is basically a revert of the to-be-fixed commit with some
checkpatch improvements.

Fixes: 735668f ("i2c: core: Allocate temp client on the stack in i2c_detect")
Signed-off-by: Geert Uytterhoeven <[email protected]>
Reviewed-by: Su Hui <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
[wsa: updated commit message, merged tags from similar patch]
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
geertu authored and Wolfram Sang committed Feb 22, 2025
1 parent 0ad2507 commit 781813d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions drivers/i2c/i2c-core-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ static int i2c_detect_address(struct i2c_client *temp_client,
static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
{
const unsigned short *address_list;
struct i2c_client temp_client;
struct i2c_client *temp_client;
int i, err = 0;

address_list = driver->address_list;
Expand All @@ -2527,19 +2527,24 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
return 0;

/* Set up a temporary client to help detect callback */
memset(&temp_client, 0, sizeof(temp_client));
temp_client.adapter = adapter;
temp_client = kzalloc(sizeof(*temp_client), GFP_KERNEL);
if (!temp_client)
return -ENOMEM;

temp_client->adapter = adapter;

for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
dev_dbg(&adapter->dev,
"found normal entry for adapter %d, addr 0x%02x\n",
i2c_adapter_id(adapter), address_list[i]);
temp_client.addr = address_list[i];
err = i2c_detect_address(&temp_client, driver);
temp_client->addr = address_list[i];
err = i2c_detect_address(temp_client, driver);
if (unlikely(err))
break;
}

kfree(temp_client);

return err;
}

Expand Down

0 comments on commit 781813d

Please sign in to comment.