Skip to content

Commit

Permalink
auxdisplay: charlcd: checking for pointer reference before dereferencing
Browse files Browse the repository at this point in the history
[ Upstream commit 4daa9ff ]

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>
  • Loading branch information
sampaio23 authored and gregkh committed Jan 11, 2022
1 parent 8a7520c commit 4ed66cd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/auxdisplay/charlcd.c
Expand Up @@ -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;
Expand Down

0 comments on commit 4ed66cd

Please sign in to comment.