Skip to content

Commit

Permalink
i2c: designware-baytrail: fix potential null pointer dereference on dev
Browse files Browse the repository at this point in the history
The assignment to addr requires a call to get_sem_addr that dereferences
dev, however, this dereference occurs before a null pointer check on dev.
Move this assignment after the null check on dev to avoid a potential null
pointer dereference.

Detected by CoverityScan, CID#1419700 ("Dereference before null check")

Fixes: fd476fa ("i2c: designware-baytrail: Add support for cherrytrail")
Signed-off-by: Colin Ian King <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
Colin Ian King authored and Wolfram Sang committed Apr 19, 2017
1 parent bd698d2 commit c7f82ea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/i2c/busses/i2c-designware-baytrail.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void reset_semaphore(struct dw_i2c_dev *dev)

static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
{
u32 addr = get_sem_addr(dev);
u32 addr;
u32 sem = PUNIT_SEMAPHORE_ACQUIRE;
int ret;
unsigned long start, end;
Expand All @@ -94,6 +94,8 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev)
*/
pm_qos_update_request(&dev->pm_qos, 0);

addr = get_sem_addr(dev);

/* host driver writes to side band semaphore register */
ret = iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, addr, sem);
if (ret) {
Expand Down

0 comments on commit c7f82ea

Please sign in to comment.