mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: fix compiler warnings
@ 2012-09-03  5:58 Alexander Aring
  2012-09-03  5:58 ` [PATCH 2/2] mtd: add private data to mtddev-hook Alexander Aring
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alexander Aring @ 2012-09-03  5:58 UTC (permalink / raw)
  To: barebox

Fix some compiler warnings.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 drivers/mtd/core.c   | 6 +++---
 drivers/mtd/mtdraw.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 5510439..3dcc908 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -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;
diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
index 24f7358..9961a75 100644
--- a/drivers/mtd/mtdraw.c
+++ b/drivers/mtd/mtdraw.c
@@ -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;
-- 
1.7.12


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mtd: add private data to mtddev-hook
  2012-09-03  5:58 [PATCH 1/2] mtd: fix compiler warnings Alexander Aring
@ 2012-09-03  5:58 ` Alexander Aring
  2012-09-03  9:06 ` [PATCH 1/2] mtd: fix compiler warnings Sascha Hauer
  2012-09-05 15:25 ` Jan Lübbe
  2 siblings, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2012-09-03  5:58 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 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(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 3dcc908..a6132e8 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -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);
diff --git a/drivers/mtd/mtd.h b/drivers/mtd/mtd.h
index c8af6e3..414bd6c 100644
--- a/drivers/mtd/mtd.h
+++ b/drivers/mtd/mtd.h
@@ -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;
 
diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c
index e4dd1a0..c7bf40c 100644
--- a/drivers/mtd/mtdoob.c
+++ b/drivers/mtd/mtdoob.c
@@ -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)
diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
index 9961a75..16157e9 100644
--- a/drivers/mtd/mtdraw.c
+++ b/drivers/mtd/mtdraw.c
@@ -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)
-- 
1.7.12


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mtd: fix compiler warnings
  2012-09-03  5:58 [PATCH 1/2] mtd: fix compiler warnings Alexander Aring
  2012-09-03  5:58 ` [PATCH 2/2] mtd: add private data to mtddev-hook Alexander Aring
@ 2012-09-03  9:06 ` Sascha Hauer
  2012-09-05 15:25 ` Jan Lübbe
  2 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-09-03  9:06 UTC (permalink / raw)
  To: Alexander Aring; +Cc: barebox

On Mon, Sep 03, 2012 at 07:58:00AM +0200, Alexander Aring wrote:
> Fix some compiler warnings.
> 
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>

Applied, thanks

Sascha

> ---
>  drivers/mtd/core.c   | 6 +++---
>  drivers/mtd/mtdraw.c | 4 ++--
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
> index 5510439..3dcc908 100644
> --- a/drivers/mtd/core.c
> +++ b/drivers/mtd/core.c
> @@ -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;
> diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
> index 24f7358..9961a75 100644
> --- a/drivers/mtd/mtdraw.c
> +++ b/drivers/mtd/mtdraw.c
> @@ -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;
> -- 
> 1.7.12
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mtd: fix compiler warnings
  2012-09-03  5:58 [PATCH 1/2] mtd: fix compiler warnings Alexander Aring
  2012-09-03  5:58 ` [PATCH 2/2] mtd: add private data to mtddev-hook Alexander Aring
  2012-09-03  9:06 ` [PATCH 1/2] mtd: fix compiler warnings Sascha Hauer
@ 2012-09-05 15:25 ` Jan Lübbe
  2012-09-05 18:53   ` Alexander Aring
  2 siblings, 1 reply; 5+ messages in thread
From: Jan Lübbe @ 2012-09-05 15:25 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Aring

Hi,

On Mon, 2012-09-03 at 07:58 +0200, Alexander Aring wrote:
> Fix some compiler warnings.
> --- a/drivers/mtd/core.c
> +++ b/drivers/mtd/core.c
> @@ -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
-- 
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mtd: fix compiler warnings
  2012-09-05 15:25 ` Jan Lübbe
@ 2012-09-05 18:53   ` Alexander Aring
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2012-09-05 18:53 UTC (permalink / raw)
  To: Jan Lübbe; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 2729 bytes --]

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 <jlu@pengutronix.de>

> Hi,
>
> On Mon, 2012-09-03 at 07:58 +0200, Alexander Aring wrote:
> > Fix some compiler warnings.
> > --- a/drivers/mtd/core.c
> > +++ b/drivers/mtd/core.c
> > @@ -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
> --
> 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 |
>
>

[-- Attachment #1.2: Type: text/html, Size: 3597 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-09-05 18:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-03  5:58 [PATCH 1/2] mtd: fix compiler warnings Alexander Aring
2012-09-03  5:58 ` [PATCH 2/2] mtd: add private data to mtddev-hook Alexander Aring
2012-09-03  9:06 ` [PATCH 1/2] mtd: fix compiler warnings Sascha Hauer
2012-09-05 15:25 ` Jan Lübbe
2012-09-05 18:53   ` Alexander Aring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox