Skip to contentSkip to conversation

mtd: fix compiler warnings

PATCH Applied Alexander Aring 3 participants 5 messages Sep 3, 2012 – Sep 5, 2012 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mtd: fix compiler warnings

Fix some compiler warnings.

---
 drivers/mtd/core.c   | 6 +++---
 drivers/mtd/mtdraw.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/mtd/core.c +3 -3
index 5510439..3dcc908 100644
@@ -79,7 +79,7 @@ static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count,
 		return -EINVAL;
 	}
 
-	dev_dbg(cdev->dev, "write: 0x%08lx 0x%08x\n", offset, count);
+	dev_dbg(cdev->dev, "write: 0x%08lx 0x%08lx\n", offset, count);
 	while (count) {
 		now = count > mtd->writesize ? mtd->writesize : count;
 
@@ -100,7 +100,7 @@ static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count,
 				ret = mtd->write(mtd, offset, now, &retlen,
 						  buf);
 			dev_dbg(cdev->dev,
-				"offset: 0x%08lx now: 0x%08x retlen: 0x%08x\n",
+				"offset: 0x%08lx now: 0x%08lx retlen: 0x%08lx\n",
 				offset, now, retlen);
 		}
 		if (ret)
@@ -174,7 +174,7 @@ int mtd_ioctl(struct cdev *cdev, int request, void *buf)
 }
 
 #ifdef CONFIG_MTD_WRITE
-static ssize_t mtd_erase(struct cdev *cdev, size_t count, loff_t offset)
+static int mtd_erase(struct cdev *cdev, size_t count, loff_t offset)
 {
 	struct mtd_info *mtd = cdev->priv;
 	struct erase_info erase;
drivers/mtd/mtdraw.c +2 -2
index 24f7358..9961a75 100644
@@ -137,7 +137,7 @@ static ssize_t mtdraw_read(struct cdev *cdev, void *buf, size_t count,
 		retlen += ret;
 	}
 	if (ret < 0)
-		printf("err %d\n", ret);
+		printf("err %lu\n", ret);
 	else
 		ret = retlen;
 	return ret;
@@ -222,7 +222,7 @@ static ssize_t mtdraw_write(struct cdev *cdev, const void *buf, size_t count,
 	}
 }
 
-static ssize_t mtdraw_erase(struct cdev *cdev, size_t count, loff_t _offset)
+static int mtdraw_erase(struct cdev *cdev, size_t count, loff_t _offset)
 {
 	struct mtd_info *mtd = to_mtd(cdev);
 	struct erase_info erase;
Signature · 7 lines
1.7.12


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/2 mtd: add private data to mtddev-hook

The mtdoob and mtdraw device don't clean up correctly. Added a private data element to hold allocated memory. Fix remove of mtdoob and mtdraw device.

---
 drivers/mtd/core.c   |  6 ++++--
 drivers/mtd/mtd.h    |  5 +++--
 drivers/mtd/mtdoob.c | 15 ++++++++++++++-
 drivers/mtd/mtdraw.c | 15 ++++++++++++++-
 4 files changed, 35 insertions(+), 6 deletions(-)
drivers/mtd/core.c +4 -2
index 3dcc908..a6132e8 100644
@@ -248,7 +248,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
 
 	list_for_each_entry(hook, &mtd_register_hooks, hook)
 		if (hook->add_mtd_device)
-			hook->add_mtd_device(mtd, devname);
+			hook->add_mtd_device(mtd, devname, &hook->priv);
 
 	return 0;
 }
@@ -259,7 +259,9 @@ int del_mtd_device (struct mtd_info *mtd)
 
 	list_for_each_entry(hook, &mtd_register_hooks, hook)
 		if (hook->del_mtd_device)
-			hook->del_mtd_device(mtd);
+			hook->del_mtd_device(mtd, &hook->priv);
+
+	devfs_remove(&mtd->cdev);
 	unregister_device(&mtd->class_dev);
 	free(mtd->param_size.value);
 	free(mtd->cdev.name);
drivers/mtd/mtd.h +3 -2
index c8af6e3..414bd6c 100644
@@ -25,8 +25,9 @@
  */
 struct mtddev_hook {
 	struct list_head hook;
-	int (*add_mtd_device)(struct mtd_info *mtd, char *devname);
-	int (*del_mtd_device)(struct mtd_info *mtd);
+	int (*add_mtd_device)(struct mtd_info *mtd, char *devname, void **priv);
+	int (*del_mtd_device)(struct mtd_info *mtd, void **priv);
+	void *priv;
 };
 struct cdev;
 
drivers/mtd/mtdoob.c +14 -1
index e4dd1a0..c7bf40c 100644
@@ -69,7 +69,7 @@ static struct file_operations mtd_ops_oob = {
 	.lseek  = dev_lseek_default,
 };
 
-static int add_mtdoob_device(struct mtd_info *mtd, char *devname)
+static int add_mtdoob_device(struct mtd_info *mtd, char *devname, void **priv)
 {
 	struct mtdoob *mtdoob;
 
@@ -80,13 +80,26 @@ static int add_mtdoob_device(struct mtd_info *mtd, char *devname)
 	mtdoob->cdev.priv = mtdoob;
 	mtdoob->cdev.dev = &mtd->class_dev;
 	mtdoob->mtd = mtd;
+	*priv = mtdoob;
 	devfs_create(&mtdoob->cdev);
 
 	return 0;
 }
 
+static int del_mtdoob_device(struct mtd_info *mtd, void **priv)
+{
+	struct mtdoob *mtdoob;
+
+	mtdoob = *priv;
+	devfs_remove(&mtdoob->cdev);
+	free(mtdoob);
+
+	return 0;
+}
+
 static struct mtddev_hook mtdoob_hook = {
 	.add_mtd_device = add_mtdoob_device,
+	.del_mtd_device = del_mtdoob_device,
 };
 
 static int __init register_mtdoob(void)
drivers/mtd/mtdraw.c +14 -1
index 9961a75..16157e9 100644
@@ -275,7 +275,7 @@ static const struct file_operations mtd_raw_fops = {
 	.lseek		= dev_lseek_default,
 };
 
-static int add_mtdraw_device(struct mtd_info *mtd, char *devname)
+static int add_mtdraw_device(struct mtd_info *mtd, char *devname, void **priv)
 {
 	struct mtdraw *mtdraw;
 
@@ -290,13 +290,26 @@ static int add_mtdraw_device(struct mtd_info *mtd, char *devname)
 	mtdraw->cdev.priv = mtdraw;
 	mtdraw->cdev.dev = &mtd->class_dev;
 	mtdraw->cdev.mtd = mtd;
+	*priv = mtdraw;
 	devfs_create(&mtdraw->cdev);
 
 	return 0;
 }
 
+static int del_mtdraw_device(struct mtd_info *mtd, void **priv)
+{
+	struct mtdraw *mtdraw;
+
+	mtdraw = *priv;
+	devfs_remove(&mtdraw->cdev);
+	free(mtdraw);
+
+	return 0;
+}
+
 static struct mtddev_hook mtdraw_hook = {
 	.add_mtd_device = add_mtdraw_device,
+	.del_mtd_device = del_mtdraw_device,
 };
 
 static int __init register_mtdraw(void)
Signature · 7 lines
1.7.12


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#2 lore raw
In reply to Alexander Aring
Quoted 3 lines · Alexander Aring

Fix some compiler warnings.

Applied, thanks

Sascha

Quoted 67 lines
---
 drivers/mtd/core.c   | 6 +++---
 drivers/mtd/mtdraw.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/mtd/core.c +3 -3
index 5510439..3dcc908 100644
@@ -79,7 +79,7 @@ static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count,
 		return -EINVAL;
 	}
 
-	dev_dbg(cdev->dev, "write: 0x%08lx 0x%08x\n", offset, count);
+	dev_dbg(cdev->dev, "write: 0x%08lx 0x%08lx\n", offset, count);
 	while (count) {
 		now = count > mtd->writesize ? mtd->writesize : count;
 
@@ -100,7 +100,7 @@ static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count,
 				ret = mtd->write(mtd, offset, now, &retlen,
 						  buf);
 			dev_dbg(cdev->dev,
-				"offset: 0x%08lx now: 0x%08x retlen: 0x%08x\n",
+				"offset: 0x%08lx now: 0x%08lx retlen: 0x%08lx\n",
 				offset, now, retlen);
 		}
 		if (ret)
@@ -174,7 +174,7 @@ int mtd_ioctl(struct cdev *cdev, int request, void *buf)
 }
 
 #ifdef CONFIG_MTD_WRITE
-static ssize_t mtd_erase(struct cdev *cdev, size_t count, loff_t offset)
+static int mtd_erase(struct cdev *cdev, size_t count, loff_t offset)
 {
 	struct mtd_info *mtd = cdev->priv;
 	struct erase_info erase;
drivers/mtd/mtdraw.c +2 -2
index 24f7358..9961a75 100644
@@ -137,7 +137,7 @@ static ssize_t mtdraw_read(struct cdev *cdev, void *buf, size_t count,
 		retlen += ret;
 	}
 	if (ret < 0)
-		printf("err %d\n", ret);
+		printf("err %lu\n", ret);
 	else
 		ret = retlen;
 	return ret;
@@ -222,7 +222,7 @@ static ssize_t mtdraw_write(struct cdev *cdev, const void *buf, size_t count,
 	}
 }
 
-static ssize_t mtdraw_erase(struct cdev *cdev, size_t count, loff_t _offset)
+static int mtdraw_erase(struct cdev *cdev, size_t count, loff_t _offset)
 {
 	struct mtd_info *mtd = to_mtd(cdev);
 	struct erase_info erase;
Signature · 7 lines
1.7.12


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
In reply to Alexander Aring

Hi,

drivers/mtd/core.c static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count, · line 83

Quoted 10 lines · Alexander Aring

Fix some compiler warnings.

drivers/mtd/core.c +1 -1
@@ -79,7 +79,7 @@ static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count,
 		return -EINVAL;
 	}
 
-	dev_dbg(cdev->dev, "write: 0x%08lx 0x%08x\n", offset, count);
+	dev_dbg(cdev->dev, "write: 0x%08lx 0x%08lx\n", offset, count);
 	while (count) {

This causes some new warnings for me:
drivers/mtd/core.c: In function 'mtd_write':
drivers/mtd/core.c:82:2: warning: format '%08lx' expects type 'long unsigned int', but argument 5 has type 'size_t' drivers/mtd/core.c:102:4: warning: format '%08lx' expects type 'long unsigned int', but argument 5 has type 'size_t' drivers/mtd/core.c:102:4: warning: format '%08lx' expects type 'long unsigned int', but argument 6 has type 'size_t'

They go away when reverting this. It seems that different achitectures have different ideas about size_t:
./include/linux/types.h:54:typedef __kernel_size_t size_t;
./arch/ppc/include/asm/posix_types.h:17:typedef unsigned int __kernel_size_t;
./arch/blackfin/include/asm/posix_types.h:45:typedef unsigned int __kernel_size_t;
./arch/mips/include/asm/posix_types.h:34:typedef unsigned int __kernel_size_t;
./arch/mips/include/asm/posix_types.h:39:typedef unsigned long __kernel_size_t;
./arch/x86/include/asm/posix_types.h:34:typedef unsigned int __kernel_size_t;
./arch/sandbox/include/asm/posix_types.h:18:typedef unsigned long __kernel_size_t;
./arch/nios2/include/asm/posix_types.h:30:typedef unsigned int __kernel_size_t;
./arch/openrisc/include/asm/posix_types.h:28:typedef unsigned int __kernel_size_t;
./arch/arm/include/asm/posix_types.h:30:typedef unsigned int __kernel_size_t;

On which arch did you see the warnings with the original code?

Regards,
Jan

Signature · 10 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Hi,

I saw it on sandbox platform. Does this depend on 32 bit or 64 bit system?

I found this for __kernel_size_t:
arch/sandbox/include/asm/posix_types.h:18:typedef unsigned long __kernel_size_t;

so we need to change this to:
typedef unsigned int __kernel_size_t;

but in mips arch there is unsigned long, too.

Regards
Alex

2012/9/5 Jan Lübbe <[email protected]>

Quoted 48 lines

Hi,

drivers/mtd/core.c static ssize_t mtd_write(struct cdev* cdev, const void

Quoted 4 lines · Alexander Aring

Fix some compiler warnings.

drivers/mtd/core.c +0 -0
@@ -79,7 +79,7 @@ static ssize_t mtd_write(struct cdev* cdev, const void

*buf, size_t _count,

drivers/mtd/core.c static ssize_t mtd_write(struct cdev* cdev, const void *buf, size_t _count, · line 83

Quoted 6 lines
drivers/mtd/core.c +1 -1
              return -EINVAL;
      }
 
-     dev_dbg(cdev->dev, "write: 0x%08lx 0x%08x\n", offset, count);
+     dev_dbg(cdev->dev, "write: 0x%08lx 0x%08lx\n", offset, count);
      while (count) {

This causes some new warnings for me:
drivers/mtd/core.c: In function 'mtd_write':
drivers/mtd/core.c:82:2: warning: format '%08lx' expects type 'long unsigned int', but argument 5 has type 'size_t' drivers/mtd/core.c:102:4: warning: format '%08lx' expects type 'long unsigned int', but argument 5 has type 'size_t' drivers/mtd/core.c:102:4: warning: format '%08lx' expects type 'long unsigned int', but argument 6 has type 'size_t'

They go away when reverting this. It seems that different achitectures have different ideas about size_t:
./include/linux/types.h:54:typedef __kernel_size_t size_t;
./arch/ppc/include/asm/posix_types.h:17:typedef unsigned int
__kernel_size_t;
./arch/blackfin/include/asm/posix_types.h:45:typedef unsigned int __kernel_size_t; ./arch/mips/include/asm/posix_types.h:34:typedef unsigned int __kernel_size_t; ./arch/mips/include/asm/posix_types.h:39:typedef unsigned long
__kernel_size_t;
./arch/x86/include/asm/posix_types.h:34:typedef unsigned int
__kernel_size_t;
./arch/sandbox/include/asm/posix_types.h:18:typedef unsigned long __kernel_size_t; ./arch/nios2/include/asm/posix_types.h:30:typedef unsigned int
__kernel_size_t;
./arch/openrisc/include/asm/posix_types.h:28:typedef unsigned int __kernel_size_t; ./arch/arm/include/asm/posix_types.h:30:typedef unsigned int
__kernel_size_t;

On which arch did you see the warnings with the original code?

Quoted 9 lines

Regards,
Jan
--

Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox