From: Luiz Sampaio Date: Tue, 9 Nov 2021 22:07:32 +0000 (-0300) Subject: auxdisplay: charlcd: checking for pointer reference before dereferencing X-Git-Tag: baikal/mips/sdk6.1~6799^2 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=fc591bce9f52b59a6d0c5af4713586509a4a80cc;p=kernel.git auxdisplay: charlcd: checking for pointer reference before dereferencing 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 Signed-off-by: Miguel Ojeda --- diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c index cca3b600c0ba7..6d309e4971b61 100644 --- a/drivers/auxdisplay/charlcd.c +++ b/drivers/auxdisplay/charlcd.c @@ -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;