summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Sampaio <sampaio.ime@gmail.com>2021-11-09 23:07:32 +0100
committerMiguel Ojeda <ojeda@kernel.org>2021-11-24 11:46:52 +0100
commit4daa9ff89ef27be43c15995412d6aee393a78200 (patch)
tree6be42ed28dfed32cd06e1bfcf334246827a8bd3a
parentauxdisplay: charlcd: fixing coding style issue (diff)
downloadlinux-4daa9ff89ef27be43c15995412d6aee393a78200.tar.xz
linux-4daa9ff89ef27be43c15995412d6aee393a78200.zip
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 <sampaio.ime@gmail.com> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
-rw-r--r--drivers/auxdisplay/charlcd.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
index cca3b600c0ba..6d309e4971b6 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;