]> git.baikalelectronics.ru Git - kernel.git/commitdiff
auxdisplay: charlcd: checking for pointer reference before dereferencing
authorLuiz Sampaio <sampaio.ime@gmail.com>
Tue, 9 Nov 2021 22:07:32 +0000 (19:07 -0300)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 24 Nov 2021 10:46:52 +0000 (11:46 +0100)
Check if the pointer lcd->ops->init_display exists before dereferencing it.
If a driver called charlcd_init() without defining the ops, this would
return segmentation fault, as happened to me when implementing a charlcd
driver.  Checking the pointer before dereferencing protects from
segmentation fault.

Signed-off-by: Luiz Sampaio <sampaio.ime@gmail.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
drivers/auxdisplay/charlcd.c

index cca3b600c0ba769ba38c8e2a9aed39d5152c33f3..6d309e4971b617ded2c7eecc26fbe3a88ed2a015 100644 (file)
@@ -578,6 +578,9 @@ static int charlcd_init(struct charlcd *lcd)
         * Since charlcd_init_display() needs to write data, we have to
         * enable mark the LCD initialized just before.
         */
+       if (WARN_ON(!lcd->ops->init_display))
+               return -EINVAL;
+
        ret = lcd->ops->init_display(lcd);
        if (ret)
                return ret;