Fixing bug that would segmentation fault
cover Fixing bug that would segmentation fault
This series of patches consists of one patch fixing a simple coding style issue and one patch fixing a bug that would cause segmentation fault. Basically, there was a pointer that was being dereferenced without testing if the pointer exists. This patch adds a protection, returning EFAULT in case the pointer is NULL.
Luiz Sampaio (2):
auxdisplay: charlcd: fixing coding style issue
auxdisplay: charlcd: checking for pointer reference before
dereferencing
drivers/auxdisplay/charlcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.33.1
PATCH 1/2 auxdisplay: charlcd: fixing coding style issue
Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
--- drivers/auxdisplay/charlcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/charlcd.c +1 -1
@@ -37,7 +37,7 @@ struct charlcd_priv {bool must_clear;/* contains the LCD config state */ -unsigned long int flags; +unsigned long flags;/* Current escape sequence and it's length or -1 if outside */ struct {
Signature · 1 line
2.33.1
Re: [PATCH 1/2] auxdisplay: charlcd: fixing coding style issue
Quoted 2 lines · Luiz Sampaio
Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
Not sure if this is a rule, but it is good to be consistent with the rest of auxdisplay. Thanks!
Cheers,
Miguel
PATCH 2/2 auxdisplay: charlcd: checking for pointer reference before dereferencing
In reply to Luiz SampaioCheck 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.
--- drivers/auxdisplay/charlcd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/auxdisplay/charlcd.c +3 -0
@@ -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 (!lcd->ops->init_display) +return -EFAULT ; + ret = lcd->ops->init_display (lcd);if (ret)return ret;
Signature · 1 line
2.33.1
Re: [PATCH 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
Quoted 6 lines · Luiz Sampaio
Check if the pointer
lcd->ops->init_displayexists before dereferencing it. If a driver calledcharlcd_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.
It can't hurt -- thanks! I think EINVAL makes more sense here, also we could use WARN_ON:
if (WARN_ON(!lcd->ops->init_display))
return -EINVAL;Cheers,
Miguel
v2 cover Fixing bug that would segmentation fault
This series of patches consists of one patch fixing a simple coding style issue and one patch fixing a bug that would cause segmentation fault. Basically, there was a pointer that was being dereferenced without testing if the pointer exists. This patch adds a protection, returning EFAULT in case the pointer is NULL.
Changes in v2:
- Changed return to -EINVAL and using WARN_ON as suggested
- Note in response for Miguel's comment: for the first patch, I ran the script './scripts/checkpatch.pl --file --terse' to see with the file
had any coding style issue. That was when I was suggested to remove 'int' from 'unsigned long' declaration
Luiz Sampaio (2):
auxdisplay: charlcd: fixing coding style issue
auxdisplay: charlcd: checking for pointer reference before
dereferencing
drivers/auxdisplay/charlcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.33.1
PATCH v2 1/2 auxdisplay: charlcd: fixing coding style issue
Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
--- drivers/auxdisplay/charlcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/charlcd.c +1 -1
@@ -37,7 +37,7 @@ struct charlcd_priv {bool must_clear;/* contains the LCD config state */ -unsigned long int flags; +unsigned long flags;/* Current escape sequence and it's length or -1 if outside */ struct {
Signature · 1 line
2.33.1
Miguel Ojeda
AppliedRe: [PATCH v2 1/2] auxdisplay: charlcd: fixing coding style issue
Quoted 4 lines · Luiz Sampaio
Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
Signed-off-by Luiz Sampaio <[email protected]>
Queued up, thanks!
Cheers,
Miguel
PATCH v2 2/2 auxdisplay: charlcd: checking for pointer reference before dereferencing
In reply to Luiz SampaioCheck 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.
--- drivers/auxdisplay/charlcd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/auxdisplay/charlcd.c +3 -0
@@ -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;
Signature · 1 line
2.33.1
Miguel Ojeda
AppliedRe: [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
Quoted 8 lines · Luiz Sampaio
Check if the pointer
lcd->ops->init_displayexists before dereferencing it. If a driver calledcharlcd_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 <[email protected]>
Queued up, thanks!
Cheers,
Miguel