Skip to content

Commit 898c0a1

Browse files
andy-shevojeda
authored andcommitted
auxdisplay: lcd2s: Fix memory leak in ->remove()
Once allocated the struct lcd2s_data is never freed. Fix the memory leak by switching to devm_kzalloc(). Fixes: 8c9108d ("auxdisplay: add a driver for lcd2s character display") Cc: Lars Poeschel <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 4424c35 commit 898c0a1

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

drivers/auxdisplay/lcd2s.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ static int lcd2s_i2c_probe(struct i2c_client *i2c,
298298
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA))
299299
return -EIO;
300300

301+
lcd2s = devm_kzalloc(&i2c->dev, sizeof(*lcd2s), GFP_KERNEL);
302+
if (!lcd2s)
303+
return -ENOMEM;
304+
301305
/* Test, if the display is responding */
302306
err = lcd2s_i2c_smbus_write_byte(i2c, LCD2S_CMD_DISPLAY_OFF);
303307
if (err < 0)
@@ -307,12 +311,6 @@ static int lcd2s_i2c_probe(struct i2c_client *i2c,
307311
if (!lcd)
308312
return -ENOMEM;
309313

310-
lcd2s = kzalloc(sizeof(struct lcd2s_data), GFP_KERNEL);
311-
if (!lcd2s) {
312-
err = -ENOMEM;
313-
goto fail1;
314-
}
315-
316314
lcd->drvdata = lcd2s;
317315
lcd2s->i2c = i2c;
318316
lcd2s->charlcd = lcd;
@@ -321,24 +319,22 @@ static int lcd2s_i2c_probe(struct i2c_client *i2c,
321319
err = device_property_read_u32(&i2c->dev, "display-height-chars",
322320
&lcd->height);
323321
if (err)
324-
goto fail2;
322+
goto fail1;
325323

326324
err = device_property_read_u32(&i2c->dev, "display-width-chars",
327325
&lcd->width);
328326
if (err)
329-
goto fail2;
327+
goto fail1;
330328

331329
lcd->ops = &lcd2s_ops;
332330

333331
err = charlcd_register(lcd2s->charlcd);
334332
if (err)
335-
goto fail2;
333+
goto fail1;
336334

337335
i2c_set_clientdata(i2c, lcd2s);
338336
return 0;
339337

340-
fail2:
341-
kfree(lcd2s);
342338
fail1:
343339
kfree(lcd);
344340
return err;

0 commit comments

Comments
 (0)