diff mbox

pmc551: fix signedness bug in init_pmc551()

Message ID 1325019256-5171-1-git-send-email-xi.wang@gmail.com
State New, archived
Headers show

Commit Message

Xi Wang Dec. 27, 2011, 8:54 p.m. UTC
Since "length" is a u32, the error handling below didn't work when
fixup_pmc551() returns -ENODEV.

	if ((length = fixup_pmc551(PCI_Device)) <= 0)

This patch changes fixup_pmc551() by separating the error handling
and the size.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
---
 drivers/mtd/devices/pmc551.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

Comments

Artem Bityutskiy Jan. 9, 2012, 9:05 p.m. UTC | #1
On Tue, 2011-12-27 at 15:54 -0500, Xi Wang wrote:
> Since "length" is a u32, the error handling below didn't work when
> fixup_pmc551() returns -ENODEV.
> 
> 	if ((length = fixup_pmc551(PCI_Device)) <= 0)
> 
> This patch changes fixup_pmc551() by separating the error handling
> and the size.
> 
> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> ---
>  drivers/mtd/devices/pmc551.c |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)

You can just change the type to int without introducing a separate
argument. I think the length cannot be too large anyway. E.g., because
it is compared to "asize" which is int.

Artem.
Xi Wang Jan. 9, 2012, 9:36 p.m. UTC | #2
On Jan 9, 2012, at 4:05 PM, Artem Bityutskiy wrote:
> You can just change the type to int without introducing a separate
> argument. I think the length cannot be too large anyway. E.g., because
> it is compared to "asize" which is int.

That would work too.  Will do a v2.  Thanks.

- xi
diff mbox

Patch

diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index ecff765..17b3536 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -359,7 +359,7 @@  static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
  * mechanism
  * returns the size of the memory region found.
  */
-static u32 fixup_pmc551(struct pci_dev *dev)
+static int fixup_pmc551(struct pci_dev *dev, u32 *lenp)
 {
 #ifdef CONFIG_MTD_PMC551_BUGFIX
 	u32 dram_data;
@@ -638,7 +638,8 @@  static u32 fixup_pmc551(struct pci_dev *dev)
 		(bcmd & 0x1) ? "software" : "hardware",
 		(bcmd & 0x20) ? "" : "un", (bcmd & 0x40) ? "" : "un");
 #endif
-	return size;
+	*lenp = size;
+	return 0;
 }
 
 /*
@@ -713,7 +714,7 @@  static int __init init_pmc551(void)
 		 * with the oldproc.c driver in
 		 * some kernels (2.2.*)
 		 */
-		if ((length = fixup_pmc551(PCI_Device)) <= 0) {
+		if (fixup_pmc551(PCI_Device, &length) < 0 || !length) {
 			printk(KERN_NOTICE "pmc551: Cannot init SDRAM\n");
 			break;
 		}