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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jan 2022 14:35:17 +0000 (15:35 +0100)
[ Upstream commit 4daa9ff89ef27be43c15995412d6aee393a78200 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/auxdisplay/charlcd.c

index 304accde365c84d639a7e8597e436839751c854f..6c010d4efa4ae5d4a39bf31e3940e559e4d6efe8 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;