auxdisplay: linedisp: Free allocated resources in ->release()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 12 Feb 2024 17:01:35 +0000 (19:01 +0200)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 15 Feb 2024 11:24:54 +0000 (13:24 +0200)
While there is no issue currently with the resources allocation,
the code may still be made more robust by deallocating message
in the ->release() callback.

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/auxdisplay/line-display.c

index 03e7f10..310e9bf 100644 (file)
@@ -188,8 +188,16 @@ static struct attribute *linedisp_attrs[] = {
 };
 ATTRIBUTE_GROUPS(linedisp);
 
+static void linedisp_release(struct device *dev)
+{
+       struct linedisp *linedisp = container_of(dev, struct linedisp, dev);
+
+       kfree(linedisp->message);
+}
+
 static const struct device_type linedisp_type = {
        .groups = linedisp_groups,
+       .release = linedisp_release,
 };
 
 /**
@@ -253,7 +261,6 @@ void linedisp_unregister(struct linedisp *linedisp)
 {
        device_del(&linedisp->dev);
        del_timer_sync(&linedisp->timer);
-       kfree(linedisp->message);
        put_device(&linedisp->dev);
 }
 EXPORT_SYMBOL_GPL(linedisp_unregister);