Skip to contentSkip to conversation

HID: picoLCD: fix a NULL test in picolcd_raw_cir()

PATCH Applied Dan Carpenter 3 participants 3 messages Sep 7, 2012 – Sep 8, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: picoLCD: fix a NULL test in picolcd_raw_cir()

Smatch complains that the NULL checking in this function is not consistent and could lead to a NULL dereference. The comments say that we should return here if rc_dev is NULL so I've changed the test to match the comment.

---
Only needed in linux-next. This is a static checker fix and I don't have the hardware to test it. Please review carefully.

drivers/hid/hid-picolcd_cir.c +1 -1
index 14c5ce0..13ca919 100644
@@ -51,7 +51,7 @@ int picolcd_raw_cir(struct picolcd_data *data,
 
 	/* ignore if rc_dev is NULL or status is shunned */
 	spin_lock_irqsave(&data->lock, flags);
-	if (data->rc_dev && (data->status & PICOLCD_CIR_SHUN)) {
+	if (!data->rc_dev || (data->status & PICOLCD_CIR_SHUN)) {
 		spin_unlock_irqrestore(&data->lock, flags);
 		return 1;
 	}
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Fri, 07 September 2012 Dan Carpenter <[email protected]> wrote:

Smatch complains that the NULL checking in this function is not consistent and could lead to a NULL dereference. The comments say that we should return here if rc_dev is NULL so I've changed the test to match the comment.

Good catch! Currently thanks to HID mutex around probe()/remove() we should never be able to see rc_dev being NULL here.

Once the probe()/remove() mutex gets tied to hw_start()/hw_stop() or otherwise changed to allow drivers to chat with device during probe() ->rc_dev might be NULL in picolcd_raw_cir().

Jiri, please apply to picolcd branch.

Thanks,
Bruno

Quoted 10 lines

---
Only needed in linux-next. This is a static checker fix and I don't have the hardware to test it. Please review carefully.

drivers/hid/hid-picolcd_cir.c +0 -0
index 14c5ce0..13ca919 100644

drivers/hid/hid-picolcd_cir.c int picolcd_raw_cir(struct picolcd_data *data, · line 57

Quoted 8 lines
drivers/hid/hid-picolcd_cir.c +1 -1
@@ -51,7 +51,7 @@ int picolcd_raw_cir(struct picolcd_data *data,
 
 	/* ignore if rc_dev is NULL or status is shunned */
 	spin_lock_irqsave(&data->lock, flags);
-	if (data->rc_dev && (data->status & PICOLCD_CIR_SHUN)) {
+	if (!data->rc_dev || (data->status & PICOLCD_CIR_SHUN)) {
 		spin_unlock_irqrestore(&data->lock, flags);
 		return 1;
 	}

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Applied
#2 lore raw
Quoted 9 lines · Bruno Prémont
Quoted 4 lines

Smatch complains that the NULL checking in this function is not consistent and could lead to a NULL dereference. The comments say that we should return here if rc_dev is NULL so I've changed the test to match the comment.

Good catch! Currently thanks to HID mutex around probe()/remove() we should never be able to see rc_dev being NULL here.

Quoted 6 lines

Once the probe()/remove() mutex gets tied to hw_start()/hw_stop() or otherwise changed to allow drivers to chat with device during probe() ->rc_dev might be NULL in picolcd_raw_cir().

Applied, thanks Dan, thanks Bruno.

Signature · 2 lines
Jiri Kosina
SUSE Labs