Hi Laurent, (+Sakari) On 09/04/2020 17:33, Laurent Pinchart wrote: > Hi Kieran, > > Thank you for the patch. > > On Thu, Apr 09, 2020 at 01:11:51PM +0100, Kieran Bingham wrote: >> v8: >> - Convert probe kzalloc usage to devm_ variant > > This isn't worse than the existing code, but are you aware that devm_* > should not be used in this case ? The memory should be allocated with > kzalloc() and freed in the .release() operation. This change was at the request of a review comment from Sakari. From: https://lore.kernel.org/linux-media/4139f241-2fde-26ad-fe55-dcaeb76ad6cc@xxxxxxxxxxxxxxxx/ > >>> + >>> +static int max9286_probe(struct i2c_client *client) >>> +{ >>> + struct max9286_priv *priv; >>> + unsigned int i; >>> + int ret; >>> + >>> + priv = kzalloc(sizeof(*priv), GFP_KERNEL); >>> + if (!priv) >>> + return -ENOMEM; >> >> You won't lose anything by using the devm_ variant here. > > Indeed, > >> >>> + >>> + priv->client = client; >>> + i2c_set_clientdata(client, priv); >>> + >>> + for (i = 0; i < MAX9286_N_SINKS; i++) >>> + max9286_init_format(&priv->fmt[i]); >>> + >>> + ret = max9286_parse_dt(priv); >>> + if (ret) >>> + return ret; >> >> But you can avoid accidental memory leaks for nothing. :-) > > It would be good not to leak indeed! I understand that there are lifetime issues in V4L2 - but in my opinion that needs to be handled by core V4l2 (and or support from driver core framework). Also - isn't it highly unlikely to affect the max9286? Isn't the lifetime issue that the device can be unplugged while the file handle is open? I don't think anyone is going to 'unplug' the max9286 while it's active :-) >> --- >> drivers/media/i2c/max9286.c | 5 +---- >> 1 file changed, 1 insertion(+), 4 deletions(-) >> >> diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c >> index b84d2daa6561..0a43137b8112 100644 >> --- a/drivers/media/i2c/max9286.c >> +++ b/drivers/media/i2c/max9286.c >> @@ -1155,7 +1155,7 @@ static int max9286_probe(struct i2c_client *client) >> unsigned int i; >> int ret; >> >> - priv = kzalloc(sizeof(*priv), GFP_KERNEL); >> + priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); >> if (!priv) >> return -ENOMEM; >> >> @@ -1232,7 +1232,6 @@ static int max9286_probe(struct i2c_client *client) >> max9286_configure_i2c(priv, false); >> err_free: >> max9286_cleanup_dt(priv); >> - kfree(priv); >> >> return ret; >> } >> @@ -1253,8 +1252,6 @@ static int max9286_remove(struct i2c_client *client) >> >> gpiod_set_value_cansleep(priv->gpiod_pwdn, 0); >> >> - kfree(priv); >> - >> return 0; >> } >> >