Skip to content

Commit

Permalink
mfd: menelaus: Remove null pointer dereference
Browse files Browse the repository at this point in the history
If vtg is NULL, it is not possible to access its mode_reg field. At all
sites where the static function menelaus_set_voltage is called, the first
argument is the address of a structure defined in the file. So, the null
test is unnecessary and is removed. Also, a label is done away with.

This problem was found using the following Coccinelle semantic match:

// <smpl>
@@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

* if (E == NULL)
{
  ... when != if (E == NULL) S1 else S2
      when != E = E1
* E->f
  ... when any
  return ...;
}
else S3
// </smpl>

Signed-off-by: Himangi Saraogi <[email protected]>
Acked-by: Julia Lawall <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
  • Loading branch information
himangi774 authored and Lee Jones committed Sep 26, 2014
1 parent 7821d9b commit e0c8a1f
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions drivers/mfd/menelaus.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,6 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
struct i2c_client *c = the_menelaus->client;

mutex_lock(&the_menelaus->lock);
if (!vtg)
goto set_voltage;

ret = menelaus_read_reg(vtg->vtg_reg);
if (ret < 0)
Expand All @@ -482,7 +480,6 @@ static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV,
ret = menelaus_write_reg(vtg->vtg_reg, val);
if (ret < 0)
goto out;
set_voltage:
ret = menelaus_write_reg(vtg->mode_reg, mode);
out:
mutex_unlock(&the_menelaus->lock);
Expand Down

0 comments on commit e0c8a1f

Please sign in to comment.