Commit abfd324f authored by Jean Delvare's avatar Jean Delvare Committed by Deepak Saxena

[PATCH] I2C: Fix memory leaks in w83781d and asb100

Quoting myself

> U-ho. I think I've introduced a memory leak with this patch :(
>
> For drivers that handle subclients (asb100 and w83781d on i2c), the
> sublient memory is never released if I read the code correctly. This
> is because we now free the private data on unload, assuming that it
> contains the i2c client data as well. That's true for the main i2c
> client, but not for the subclients (data == NULL so nothing is freed).
>
> Could someone take a look and confirm?

I could test and actually saw memory leaking when cycling the w83781d
driver at a sustained rate (5/s).

> I can see two different fixes:
>
> 1* When freeing the memory, free the data if it's not NULL (main
> client), else free client (subclients). Cleaner (I suppose?).
>
> 2* When creating subclients, do data = &client instead of data = NULL.
> Then freeing will work. Less code, faster. Are there side effects? (I
> don't think so)
>
> My preference would go to 2*.

I ended up implementing 1*. That's cleaner and there's actually almost
no extra code.

Mark, can you confirm that I'm doing the correct thing? I'll do
something similar in our CVS repository (for now, the asb100 and w83781d
drivers had not their memory allocation scheme reworked there).
parent 06ad1312
...@@ -855,7 +855,13 @@ static int asb100_detach_client(struct i2c_client *client) ...@@ -855,7 +855,13 @@ static int asb100_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(i2c_get_clientdata(client)); if (i2c_get_clientdata(client)==NULL) {
/* subclients */
kfree(client);
} else {
/* main client */
kfree(i2c_get_clientdata(client));
}
return 0; return 0;
} }
......
...@@ -1336,7 +1336,13 @@ w83781d_detach_client(struct i2c_client *client) ...@@ -1336,7 +1336,13 @@ w83781d_detach_client(struct i2c_client *client)
return err; return err;
} }
kfree(i2c_get_clientdata(client)); if (i2c_get_clientdata(client)==NULL) {
/* subclients */
kfree(client);
} else {
/* main client */
kfree(i2c_get_clientdata(client));
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment