mtd/drivers/mtd mtdchar.c,1.60,1.61
David Woodhouse
dwmw2 at infradead.org
Mon Jul 12 09:02:44 EDT 2004
Update of /home/cvs/mtd/drivers/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv24469
Modified Files:
mtdchar.c
Log Message:
Merge from 2.6: sparse annotations.
cleanup devfs crap.
Index: mtdchar.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtdchar.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- mtdchar.c 19 Jun 2004 17:31:26 -0000 1.60
+++ mtdchar.c 12 Jul 2004 13:02:41 -0000 1.61
@@ -17,20 +17,46 @@
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h>
-static void mtd_notify_add(struct mtd_info* mtd);
-static void mtd_notify_remove(struct mtd_info* mtd);
+
+static void mtd_notify_add(struct mtd_info* mtd)
+{
+ if (!mtd)
+ return;
+
+ devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
+ S_IFCHR | S_IRUGO | S_IWUGO, "mtd/%d", mtd->index);
+
+ devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
+ S_IFCHR | S_IRUGO, "mtd/%dro", mtd->index);
+}
+
+static void mtd_notify_remove(struct mtd_info* mtd)
+{
+ if (!mtd)
+ return;
+ devfs_remove("mtd/%d", mtd->index);
+ devfs_remove("mtd/%dro", mtd->index);
+}
static struct mtd_notifier notifier = {
.add = mtd_notify_add,
.remove = mtd_notify_remove,
};
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-static devfs_handle_t devfs_dir_handle;
-static devfs_handle_t devfs_rw_handle[MAX_MTD_DEVICES];
-static devfs_handle_t devfs_ro_handle[MAX_MTD_DEVICES];
-#endif
+static inline void mtdchar_devfs_init(void);
+{
+ devfs_mk_dir("mtd");
+ register_mtd_user(¬ifier);
+}
+static inline void mtdchar_devfs_exit(void)
+{
+ unregister_mtd_user(¬ifier);
+ devfs_remove("mtd");
+}
+#else /* !DEVFS */
+#define mtdchar_devfs_init() do { } while(0)
+#define mtdchar_devfs_exit() do { } while(0)
#endif
static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
@@ -123,7 +149,7 @@
*/
#define MAX_KMALLOC_SIZE 0x20000
-static ssize_t mtd_read(struct file *file, char *buf, size_t count,loff_t *ppos)
+static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos)
{
struct mtd_info *mtd = (struct mtd_info *)file->private_data;
size_t retlen=0;
@@ -176,7 +202,7 @@
return total_retlen;
} /* mtd_read */
-static ssize_t mtd_write(struct file *file, const char *buf, size_t count,loff_t *ppos)
+static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos)
{
struct mtd_info *mtd = (struct mtd_info *)file->private_data;
char *kbuf;
@@ -245,6 +271,7 @@
u_int cmd, u_long arg)
{
struct mtd_info *mtd = (struct mtd_info *)file->private_data;
+ void __user *argp = (void __user *)arg;
int ret = 0;
u_long size;
@@ -252,17 +279,17 @@
size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
if (cmd & IOC_IN) {
- ret = verify_area(VERIFY_READ, (char *)arg, size);
+ ret = verify_area(VERIFY_READ, argp, size);
if (ret) return ret;
}
if (cmd & IOC_OUT) {
- ret = verify_area(VERIFY_WRITE, (char *)arg, size);
+ ret = verify_area(VERIFY_WRITE, argp, size);
if (ret) return ret;
}
switch (cmd) {
case MEMGETREGIONCOUNT:
- if (copy_to_user((int *) arg, &(mtd->numeraseregions), sizeof(int)))
+ if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int)))
return -EFAULT;
break;
@@ -270,24 +297,19 @@
{
struct region_info_user ur;
- if (copy_from_user( &ur,
- (struct region_info_user *)arg,
- sizeof(struct region_info_user))) {
+ if (copy_from_user(&ur, argp, sizeof(struct region_info_user)))
return -EFAULT;
- }
if (ur.regionindex >= mtd->numeraseregions)
return -EINVAL;
- if (copy_to_user((struct mtd_erase_region_info *) arg,
- &(mtd->eraseregions[ur.regionindex]),
+ if (copy_to_user(argp, &(mtd->eraseregions[ur.regionindex]),
sizeof(struct mtd_erase_region_info)))
return -EFAULT;
break;
}
case MEMGETINFO:
- if (copy_to_user((struct mtd_info *)arg, mtd,
- sizeof(struct mtd_info_user)))
+ if (copy_to_user(argp, mtd, sizeof(struct mtd_info_user)))
return -EFAULT;
break;
@@ -308,7 +330,7 @@
init_waitqueue_head(&waitq);
memset (erase,0,sizeof(struct erase_info));
- if (copy_from_user(&erase->addr, (u_long *)arg,
+ if (copy_from_user(&erase->addr, argp,
sizeof(struct erase_info_user))) {
kfree(erase);
return -EFAULT;
@@ -352,7 +374,7 @@
if(!(file->f_mode & 2))
return -EPERM;
- if (copy_from_user(&buf, (struct mtd_oob_buf *)arg, sizeof(struct mtd_oob_buf)))
+ if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
return -EFAULT;
if (buf.length > 0x4096)
@@ -361,7 +383,7 @@
if (!mtd->write_oob)
ret = -EOPNOTSUPP;
else
- ret = verify_area(VERIFY_READ, (char *)buf.ptr, buf.length);
+ ret = verify_area(VERIFY_READ, buf.ptr, buf.length);
if (ret)
return ret;
@@ -377,7 +399,7 @@
ret = (mtd->write_oob)(mtd, buf.start, buf.length, &retlen, databuf);
- if (copy_to_user((void *)arg + sizeof(u_int32_t), &retlen, sizeof(u_int32_t)))
+ if (copy_to_user(argp + sizeof(uint32_t), &retlen, sizeof(uint32_t)))
ret = -EFAULT;
kfree(databuf);
@@ -391,7 +413,7 @@
void *databuf;
ssize_t retlen;
- if (copy_from_user(&buf, (struct mtd_oob_buf *)arg, sizeof(struct mtd_oob_buf)))
+ if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
return -EFAULT;
if (buf.length > 0x4096)
@@ -400,7 +422,7 @@
if (!mtd->read_oob)
ret = -EOPNOTSUPP;
else
- ret = verify_area(VERIFY_WRITE, (char *)buf.ptr, buf.length);
+ ret = verify_area(VERIFY_WRITE, buf.ptr, buf.length);
if (ret)
return ret;
@@ -411,7 +433,7 @@
ret = (mtd->read_oob)(mtd, buf.start, buf.length, &retlen, databuf);
- if (copy_to_user((void *)arg + sizeof(u_int32_t), &retlen, sizeof(u_int32_t)))
+ if (put_user(retlen, (uint32_t __user *)argp))
ret = -EFAULT;
else if (retlen && copy_to_user(buf.ptr, databuf, retlen))
ret = -EFAULT;
@@ -424,7 +446,7 @@
{
struct erase_info_user info;
- if (copy_from_user(&info ,(void *)arg, sizeof(info)))
+ if (copy_from_user(&info, argp, sizeof(info)))
return -EFAULT;
if (!mtd->lock)
@@ -438,7 +460,7 @@
{
struct erase_info_user info;
- if (copy_from_user(&info, (void *)arg, sizeof(info)))
+ if (copy_from_user(&info, argp, sizeof(info)))
return -EFAULT;
if (!mtd->unlock)
@@ -450,14 +472,14 @@
case MEMSETOOBSEL:
{
- if (copy_from_user(&mtd->oobinfo ,(void *)arg, sizeof(struct nand_oobinfo)))
+ if (copy_from_user(&mtd->oobinfo, argp, sizeof(struct nand_oobinfo)))
return -EFAULT;
break;
}
case MEMGETOOBSEL:
{
- if (copy_to_user((struct nand_oobinfo *) arg, &(mtd->oobinfo), sizeof(struct nand_oobinfo)))
+ if (copy_to_user(argp, &(mtd->oobinfo), sizeof(struct nand_oobinfo)))
return -EFAULT;
break;
}
@@ -466,7 +488,7 @@
{
loff_t offs;
- if (copy_from_user(&offs ,(void *)arg, sizeof(loff_t)))
+ if (copy_from_user(&offs, argp, sizeof(loff_t)))
return -EFAULT;
if (!mtd->block_isbad)
ret = -EOPNOTSUPP;
@@ -479,7 +501,7 @@
{
loff_t offs;
- if (copy_from_user(&offs ,(void *)arg, sizeof(loff_t)))
+ if (copy_from_user(&offs, argp, sizeof(loff_t)))
return -EFAULT;
if (!mtd->block_markbad)
ret = -EOPNOTSUPP;
@@ -506,100 +528,21 @@
.release = mtd_close,
};
-
-#ifdef CONFIG_DEVFS_FS
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-
-/* Notification that a new device has been added. Create the devfs entry for
- * it. */
-
-static void mtd_notify_add(struct mtd_info* mtd)
-{
- char name[8];
-
- if (!mtd)
- return;
-
- sprintf(name, "%d", mtd->index);
- devfs_rw_handle[mtd->index] = devfs_register(devfs_dir_handle, name,
- DEVFS_FL_DEFAULT, MTD_CHAR_MAJOR, mtd->index*2,
- S_IFCHR | S_IRUGO | S_IWUGO,
- &mtd_fops, NULL);
-
- sprintf(name, "%dro", mtd->index);
- devfs_ro_handle[mtd->index] = devfs_register(devfs_dir_handle, name,
- DEVFS_FL_DEFAULT, MTD_CHAR_MAJOR, mtd->index*2+1,
- S_IFCHR | S_IRUGO,
- &mtd_fops, NULL);
-}
-
-static void mtd_notify_remove(struct mtd_info* mtd)
-{
- if (!mtd)
- return;
-
- devfs_unregister(devfs_rw_handle[mtd->index]);
- devfs_unregister(devfs_ro_handle[mtd->index]);
-}
-
-#else
-
-static void mtd_notify_add(struct mtd_info* mtd)
-{
- if (!mtd)
- return;
-
- devfs_mk_cdev (MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
- S_IFCHR | S_IRUGO | S_IWUGO,
- "mtd/%d", mtd->index);
-
- devfs_mk_cdev (MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
- S_IFCHR | S_IRUGO,
- "mtd/%dro", mtd->index);
-}
-
-static void mtd_notify_remove(struct mtd_info* mtd)
-{
- if (!mtd)
- return;
-
- devfs_remove ("mtd/%d", mtd->index*2);
- devfs_remove ("mtd/%dro", mtd->index*2);
-}
-
-#endif
-#endif
-
static int __init init_mtdchar(void)
{
- if (register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops))
- {
+ if (register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops)) {
printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n",
MTD_CHAR_MAJOR);
return -EAGAIN;
}
-#ifdef CONFIG_DEVFS_FS
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
- devfs_dir_handle = devfs_mk_dir(NULL, "mtd", NULL);
-#else
- devfs_mk_dir("mtd");
-#endif
- register_mtd_user(¬ifier);
-#endif
+ mtdchar_devfs_init();
return 0;
}
static void __exit cleanup_mtdchar(void)
{
-#ifdef CONFIG_DEVFS_FS
- unregister_mtd_user(¬ifier);
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
- devfs_unregister(devfs_dir_handle);
-#else
- devfs_remove ("mtd");
-#endif
-#endif
+ mtdchar_devfs_exit();
unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
}
More information about the linux-mtd-cvs
mailing list