* [PATCH] i2c: core: Allocate temp client on the stack in i2c_detect
@ 2025-01-07 20:24 Heiner Kallweit
2025-01-09 10:25 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Heiner Kallweit @ 2025-01-07 20:24 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c@vger.kernel.org
The temp client is used only in scope of this function, so there's no
benefit in dynamic allocation.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/i2c/i2c-core-base.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index c21a16aa9..39de0e485 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -2461,7 +2461,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;
@@ -2482,22 +2482,19 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
return 0;
/* Set up a temporary client to help detect callback */
- temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
- if (!temp_client)
- return -ENOMEM;
- temp_client->adapter = adapter;
+ memset(&temp_client, 0, sizeof(temp_client));
+ 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;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: core: Allocate temp client on the stack in i2c_detect
2025-01-07 20:24 [PATCH] i2c: core: Allocate temp client on the stack in i2c_detect Heiner Kallweit
@ 2025-01-09 10:25 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2025-01-09 10:25 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: Wolfram Sang, linux-i2c@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
On Tue, Jan 07, 2025 at 09:24:29PM +0100, Heiner Kallweit wrote:
> The temp client is used only in scope of this function, so there's no
> benefit in dynamic allocation.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-09 10:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07 20:24 [PATCH] i2c: core: Allocate temp client on the stack in i2c_detect Heiner Kallweit
2025-01-09 10:25 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox