Skip to contentSkip to conversation

cbus-retu-wdt: Fix bitfield access

PATCH In review Michael Buesch 2 participants 5 messages Mar 2, 2011 – Mar 3, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cbus-retu-wdt: Fix bitfield access

An unsigned int pointer must not be casted to an unsigned long pointer before use. Convert the bitfield to unsigned long to fix this.
Also use clear_bit() in the release path.

---

drivers/cbus/retu-wdt.c +3 -4
Index: linux-2.6.38-rc6/drivers/cbus/retu-wdt.c
===================================================================
@@ -56,7 +56,7 @@ static int counter_param = RETU_WDT_MAX_
 
 struct retu_wdt_dev {
 	struct device		*dev;
-	int			users;
+	unsigned long		users;
 	struct miscdevice	retu_wdt_miscdev;
 	struct delayed_work	ping_work;
 };
@@ -161,7 +161,7 @@ static DEVICE_ATTR(counter, S_IRUGO, ret
 
 static int retu_wdt_open(struct inode *inode, struct file *file)
 {
-	if (test_and_set_bit(1, (unsigned long *)&(retu_wdt->users)))
+	if (test_and_set_bit(0, &retu_wdt->users))
 		return -EBUSY;
 
 	file->private_data = (void *)retu_wdt;
@@ -177,7 +177,7 @@ static int retu_wdt_release(struct inode
 #ifndef CONFIG_WATCHDOG_NOWAYOUT
 	retu_wdt_ping_enable(retu_wdt);
 #endif
-	wdev->users = 0;
+	clear_bit(0, &retu_wdt->users);
 
 	return 0;
 }
@@ -264,7 +264,6 @@ static int __init retu_wdt_probe(struct
 		return -ENOMEM;
 
 	wdev->dev = &pdev->dev;
-	wdev->users = 0;
 
 	ret = device_create_file(&pdev->dev, &dev_attr_period);
 	if (ret) {
Signature · 1 line
Greetings, Michael.
#1 lore raw
Quoted 6 lines · Michael Buesch

An unsigned int pointer must not be casted to an unsigned long pointer before use. Convert the bitfield to unsigned long to fix this.
Also use clear_bit() in the release path.

This looks ok, I'm just wondering if the change on test_and_set_bit() from bit 1 to bit 0 should be on this patch. I guess not.

Signature · 1 line
balbi
#2 lore raw
Quoted 10 lines · Felipe Balbi
Quoted 6 lines · Michael Buesch

An unsigned int pointer must not be casted to an unsigned long pointer before use. Convert the bitfield to unsigned long to fix this.
Also use clear_bit() in the release path.

This looks ok, I'm just wondering if the change on test_and_set_bit() from bit 1 to bit 0 should be on this patch. I guess not.

Uh, well. If that's worth doing a separate patch, I'll do it. It doesn't actually really matter if we use bit 0, 1 or ... for this. I just thought it was weird to use the second bit.

Signature · 1 line
Greetings Michael.
#3 lore raw
Quoted 7 lines · Michael Büsch
Quoted 6 lines · Felipe Balbi
Quoted 5 lines · Michael Buesch

An unsigned int pointer must not be casted to an unsigned long pointer before use. Convert the bitfield to unsigned long to fix this.
Also use clear_bit() in the release path.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This looks ok, I'm just wondering if the change on test_and_set_bit() from bit 1 to bit 0 should be on this patch. I guess not.

Uh, well. If that's worth doing a separate patch, I'll do it. It doesn't actually really matter if we use bit 0, 1 or ... for this. I just thought it was weird to use the second bit.

yeah, I didn't read the whole code before making the comment, if you're sure no-one is using bit 0, then go for it. Having it separate, would help on bisecting should things go wrong.

Signature · 5 lines
balbi
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
Quoted 13 lines · Felipe Balbi
Quoted 12 lines · Michael Büsch
Quoted 10 lines · Felipe Balbi
Quoted 6 lines · Michael Buesch

An unsigned int pointer must not be casted to an unsigned long pointer before use. Convert the bitfield to unsigned long to fix this.
Also use clear_bit() in the release path.

This looks ok, I'm just wondering if the change on test_and_set_bit() from bit 1 to bit 0 should be on this patch. I guess not.

Quoted 7 lines
Quoted 3 lines

Uh, well. If that's worth doing a separate patch, I'll do it. It doesn't actually really matter if we use bit 0, 1 or ... for this. I just thought it was weird to use the second bit.

yeah, I didn't read the whole code before making the comment, if you're sure no-one is using bit 0, then go for it. Having it separate, would help on bisecting should things go wrong.

All users of the bitfield (two) are visible in the patch ;)

Signature · 6 lines
Greetings Michael.

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