mtd: get rid of direct mtd->func use
Subsystems (5)
cover mtd: get rid of direct mtd->func use
Hi,
this patch-set goes on top of the "MTD API rework" patches which I sent recently:
http://lists.infradead.org/pipermail/linux-mtd/2011-December/039031.html
This patch-set further removes direct mtd function pointers accesses like:
if (mtd->block_isbad)
blah
This is a part of the big MTD API re-work we have started. The next steps will be:
1. Rename all the function pointers to make sure we catch all direct uses:
(s/mtd->func/mtd->_func/g)
2. Move common input parameters check from implementations to the wrapper function to get rid of duplication.
Artem.
PATCH 1/17 mtd: introduce mtd_has_oob helper
From: Artem Bityutskiy <[email protected]>
We are working in the direction of making sure that MTD clients to not use 'mtd->func' pointers directly. In some places we want to know if OOB operations are supported by an MTD device. Introduce 'mtd_has_oob()' helper for these purposes.
--- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/sm_ftl.c | 4 ++-- include/linux/mtd/mtd.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-)
drivers/mtd/mtdchar.c +1 -1
@@ -1004,7 +1004,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)break ;case MTD_FILE_MODE_RAW : -if (!mtd->read_oob || !mtd->write_oob) +if (!mtd_has_oob (mtd))return -EOPNOTSUPP ; mfi->mode = arg;
drivers/mtd/sm_ftl.c +2 -2
@@ -645,8 +645,8 @@ int sm_get_media_info(struct sm_ftl *ftl, struct mtd_info *mtd)if (!ftl->smallpagenand && mtd->oobsize <SM_OOB_SIZE )return -ENODEV ; -/* We use these functions for IO */ -if (!mtd->read_oob || !mtd->write_oob) +/* We use OOB */ +if (!mtd_has_oob (mtd))return -ENODEV ;/* Find geometry information */
include/linux/mtd/mtd.h +5 -0
@@ -454,6 +454,11 @@ static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)return do_div (sz, mtd->writesize); } +static inline int mtd_has_oob (const struct mtd_info *mtd) +{ +return mtd->read_oob && mtd->write_oob; +} +/* Kernel-side ioctl definitions */ struct mtd_partition ;
Signature · 1 line
1.7.7.3
PATCH 2/17 mtd: do use mtd->point directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Remove direct usage of the "mtd->point" function pointer. Instead, test the mtd_point() return code for '-EOPNOTSUPP'.
--- fs/jffs2/erase.c | 9 ++++----- fs/jffs2/readinode.c | 18 ++++++++---------- fs/jffs2/scan.c | 2 +- include/linux/mtd/mtd.h | 2 ++ 4 files changed, 15 insertions(+), 16 deletions(-)
fs/jffs2/erase.c +4 -5
@@ -336,12 +336,11 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebluint32_t ofs;size_t retlen;int ret = -EIO ; +unsigned long *wordebuf; -if (c->mtd->point) { -unsigned long *wordebuf; - - ret =mtd_point (c->mtd, jeb->offset, c->sector_size, &retlen, - &ebuf,NULL ); + ret =mtd_point (c->mtd, jeb->offset, c->sector_size, &retlen, + &ebuf,NULL ); +if (ret != -EOPNOTSUPP ) {if (ret) {D1 (printk (KERN_DEBUG "MTD point failed %d\n" , ret)); goto do_flash_read;
fs/jffs2/readinode.c +8 -10
@@ -62,17 +62,15 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info#ifndef __ECOS/* TODO: instead, incapsulate point() stuff to jffs2_flash_read(), * adding and jffs2_flash_read_end() interface. */ -if (c->mtd->point) { - err =mtd_point (c->mtd, ofs, len, &retlen, (void **)&buffer, -NULL ); -if (!err && retlen < len) { -JFFS2_WARNING ("MTD point returned len too short: %zu instead of %u.\n" , retlen, tn->csize); -mtd_unpoint (c->mtd, ofs, retlen); - }else if (err) + err =mtd_point (c->mtd, ofs, len, &retlen, (void **)&buffer,NULL ); +if (!err && retlen < len) { +JFFS2_WARNING ("MTD point returned len too short: %zu instead of %u.\n" , retlen, tn->csize); +mtd_unpoint (c->mtd, ofs, retlen); + }else if (err) { +if (err != -EOPNOTSUPP )JFFS2_WARNING ("MTD point failed: error code %d.\n" , err); -else - pointed =1 ;/* succefully pointed to device */ - } + }else + pointed =1 ;/* succefully pointed to device */ #endif if (!pointed) {
fs/jffs2/scan.c +1 -1
@@ -105,7 +105,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)mtd_unpoint (c->mtd,0 , pointlen); flashbuf = NULL; } -if (ret) +if (ret && ret != -EOPNOTSUPP )D1 (printk (KERN_DEBUG "MTD point failed %d\n" , ret)); }#endif
include/linux/mtd/mtd.h +2 -0
@@ -259,6 +259,8 @@ static inline int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, void **virt, resource_size_t *phys) { *retlen =0 ; +if (!mtd->point) +return -EOPNOTSUPP ;return mtd->point (mtd, from, len, retlen, virt, phys); }
Signature · 1 line
1.7.7.3
Re: [PATCH 02/17] mtd: do use mtd->point directly
fs/jffs2/erase.c static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl · line 338
Quoted 8 lines · Artem Bityutskiy
fs/jffs2/erase.c +0
-0@@ -336,12 +336,11 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl uint32_t ofs; size_t retlen; int ret = -EIO;
I think this initialization (ret = -EIO) was unnecessary in the first place and certainly is unnecessary now. Remove it?
fs/jffs2/erase.c static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl · line 346
Quoted 13 lines
fs/jffs2/erase.c +4
-5+ unsigned long *wordebuf; - if (c->mtd->point) { - unsigned long *wordebuf; - - ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen, - &ebuf, NULL); + ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen, + &ebuf, NULL); + if (ret != -EOPNOTSUPP) { if (ret) { D1(printk(KERN_DEBUG "MTD point failed %d\n", ret)); goto do_flash_read;
Otherwise, looks OK.
Brian
Re: [PATCH 02/17] mtd: do use mtd->point directly
Quoted 8 lines · Brian Norris
Review static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl · line 338
Quoted 5 lines
+++
b/fs/jffs2/erase.c(quoted diff) +0
-0@@ -336,12 +336,11 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl uint32_t ofs; size_t retlen; int ret = -EIO;I think this initialization (ret =
-EIO) was unnecessary in the first place and certainly is unnecessary now. Remove it?
Fair enough. I've pushed this patch to my tree:
From 162ab608ee94e01dc740c6cb55939f45aa184d44 Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <[email protected]>
Date: Tue, 10 Jan 2012 15:32:29 +0200
Subject: [PATCH] jffs2: do not initialize variable unnecessarily
Remove unnecessary initializer for a local variable.
--- fs/jffs2/erase.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/jffs2/erase.c +1 -1
@@ -335,7 +335,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_eraseblvoid *ebuf;uint32_t ofs;size_t retlen; -int ret = -EIO ; +int ret;unsigned long *wordebuf; ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen,
Signature · 5 lines
1.7.7.5 -- Best Regards, Artem Bityutskiy
PATCH 3/17 mtd: do not use mtd->get_unmapped_area directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Remove direct usage of mtd->get_unmapped_area. Instead, just call 'mtd_get_unmapped_area()' which will return -EOPNOTSUPP if the function is not implemented and test for this error code.
--- drivers/mtd/mtdchar.c | 26 +++++++++++--------------- drivers/mtd/mtdconcat.c | 6 +----- include/linux/mtd/mtd.h | 2 ++ 3 files changed, 14 insertions(+), 20 deletions(-)
drivers/mtd/mtdchar.c +11 -15
@@ -1124,25 +1124,21 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file, {struct mtd_file_info *mfi = file->private_data;struct mtd_info *mtd = mfi->mtd; +unsigned long offset; +int ret; -if (mtd->get_unmapped_area) { -unsigned long offset; - -if (addr !=0 ) -return (unsigned long ) -EINVAL ; - -if (len > mtd->size || pgoff >= (mtd->size >>PAGE_SHIFT )) -return (unsigned long ) -EINVAL ; +if (addr !=0 ) +return (unsigned long ) -EINVAL ; - offset = pgoff <<PAGE_SHIFT ; -if (offset > mtd->size - len) -return (unsigned long ) -EINVAL ; +if (len > mtd->size || pgoff >= (mtd->size >>PAGE_SHIFT )) +return (unsigned long ) -EINVAL ; -return mtd_get_unmapped_area (mtd, len, offset, flags); - } + offset = pgoff <<PAGE_SHIFT ; +if (offset > mtd->size - len) +return (unsigned long ) -EINVAL ; -/* can't map directly */ -return (unsigned long ) -ENOSYS ; + ret =mtd_get_unmapped_area (mtd, len, offset, flags); +return ret == -EOPNOTSUPP ? -ENOSYS : ret; }#endif
drivers/mtd/mtdconcat.c +1 -5
@@ -726,11 +726,7 @@ static unsigned long concat_get_unmapped_area(struct mtd_info *mtd,if (offset + len > subdev->size)return (unsigned long ) -EINVAL ; -if (subdev->get_unmapped_area) -return mtd_get_unmapped_area (subdev, len, offset, - flags); - -break ; +return mtd_get_unmapped_area (subdev, len, offset, flags); }return (unsigned long ) -ENOSYS ;
include/linux/mtd/mtd.h +2 -0
@@ -280,6 +280,8 @@ static inline unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long offset, unsigned long flags) { +if (!mtd->get_unmapped_area) +return -EOPNOTSUPP ;return mtd->get_unmapped_area (mtd, len, offset, flags); }
Signature · 1 line
1.7.7.3
PATCH 4/17 romfs: do not use mtd->get_unmapped_area directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Remove direct usage of mtd->get_unmapped_area. Instead, just call 'mtd_get_unmapped_area()' which will return -EOPNOTSUPP if the function is not implemented, and then test for this code.
We also translate -EOPNOTSUPP to -ENOSYS because this return code is probably part of the kernel ABI which we do not want to break.
--- fs/romfs/mmap-nommu.c | 28 +++++++++++++--------------- 1 files changed, 13 insertions(+), 15 deletions(-)
fs/romfs/mmap-nommu.c +13 -15
@@ -28,9 +28,10 @@ static unsigned long romfs_get_unmapped_area(struct file *file,struct inode *inode = file->f_mapping->host;struct mtd_info *mtd = inode->i_sb->s_mtd;unsigned long isize, offset, maxpages, lpages; +int ret;if (!mtd) - goto cant_map_directly; +return (unsigned long ) -ENOSYS ;/* the mapping mustn't extend beyond the EOF */ lpages = (len +PAGE_SIZE -1 ) >>PAGE_SHIFT ;
@@ -41,23 +42,20 @@ static unsigned long romfs_get_unmapped_area(struct file *file,if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))return (unsigned long ) -EINVAL ; -/* we need to call down to the MTD layer to do the actual mapping */ -if (mtd->get_unmapped_area) { -if (addr !=0 ) -return (unsigned long ) -EINVAL ; - -if (len > mtd->size || pgoff >= (mtd->size >>PAGE_SHIFT )) -return (unsigned long ) -EINVAL ; +if (addr !=0 ) +return (unsigned long ) -EINVAL ; - offset +=ROMFS_I (inode)->i_dataoffset; -if (offset > mtd->size - len) -return (unsigned long ) -EINVAL ; +if (len > mtd->size || pgoff >= (mtd->size >>PAGE_SHIFT )) +return (unsigned long ) -EINVAL ; -return mtd_get_unmapped_area (mtd, len, offset, flags); - } + offset +=ROMFS_I (inode)->i_dataoffset; +if (offset > mtd->size - len) +return (unsigned long ) -EINVAL ; -cant_map_directly: -return (unsigned long ) -ENOSYS ; + ret =mtd_get_unmapped_area (mtd, len, offset, flags); +if (ret == -EOPNOTSUPP ) + ret = -ENOSYS ; +return (unsigned long ) ret; }/*
Signature · 1 line
1.7.7.3
PATCH 5/17 mtd: mtdoops: do not use mtd->panic_write directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of checking if 'mtd->panic_write' is defined, call 'mtd_panic_write()' and check the error code - '-EOPNOTSUPP' will be returned if the function is not defined.
--- drivers/mtd/mtdoops.c | 17 ++++++++--------- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-)
drivers/mtd/mtdoops.c +8 -9
@@ -221,10 +221,14 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) hdr[0 ] = cxt->nextcount; hdr[1 ] =MTDOOPS_KERNMSG_MAGIC ; -if (panic) +if (panic) { ret =mtd_panic_write (mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); -else +if (ret == -EOPNOTSUPP ) { +printk (KERN_ERR "mtdoops: Cannot write from panic without panic_write\n" ); +return ; + } + }else ret =mtd_write (mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf);
@@ -330,13 +334,8 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,memcpy (dst + l1_cpy, s2 + s2_start, l2_cpy);/* Panics must be written immediately */ -if (reason !=KMSG_DUMP_OOPS ) { -if (!cxt->mtd->panic_write) -printk (KERN_ERR "mtdoops: Cannot write from panic without panic_write\n" ); -else -mtdoops_write (cxt,1 ); -return ; - } +if (reason !=KMSG_DUMP_OOPS ) +mtdoops_write (cxt,1 );/* For other cases, schedule work to write it "nicely" */ schedule_work (&cxt->work_write);
include/linux/mtd/mtd.h +2 -0
@@ -311,6 +311,8 @@ static inline int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { *retlen =0 ; +if (!mtd->panic_write) +return -EOPNOTSUPP ;return mtd->panic_write (mtd, to, len, retlen, buf); }
Signature · 1 line
1.7.7.3
PATCH 6/17 mtd: do not use mtd->read_oob directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of checking whether 'mtd->read_oob' is defined, just call 'mtd_read_oob()' and handle the '-EOPNOTSUPP' error which will be returned if the function is undefined.
Additionally, make 'mtd_write_oob()' return '-EOPNOTSUPP' if the function is undefined.
--- drivers/mtd/mtdchar.c | 9 ++------- include/linux/mtd/mtd.h | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/mtd/mtdchar.c +2 -7
@@ -452,13 +452,8 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,if (length >4096 )return -EINVAL ; -if (!mtd->read_oob) - ret = -EOPNOTSUPP ; -else - ret =access_ok (VERIFY_WRITE , ptr, - length) ?0 : -EFAULT ; -if (ret) -return ret; +if (!access_ok (VERIFY_WRITE , ptr, length)) +return -EFAULT ; ops.ooblen = length; ops.ooboffs = start & (mtd->writesize -1 );
include/linux/mtd/mtd.h +4 -0
@@ -320,6 +320,8 @@ static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) { ops->retlen = ops->oobretlen =0 ; +if (!mtd->read_oob) +return -EOPNOTSUPP ;return mtd->read_oob (mtd, from, ops); }
@@ -327,6 +329,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) { ops->retlen = ops->oobretlen =0 ; +if (!mtd->write_oob) +return -EOPNOTSUPP ;return mtd->write_oob (mtd, to, ops); }
Signature · 1 line
1.7.7.3
PATCH 7/17 mtd: do not use mtd->get_*_prot_info directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, call 'mtd_get_*_prot_info()' and check for '-EOPNOTSUPP'. While on it, fix the return code from '-EOPNOTSUPP' to '-EINVAL' for the case when the mode parameter is invalid.
--- drivers/mtd/mtdchar.c | 8 +++----- include/linux/mtd/mtd.h | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/mtd/mtdchar.c +3 -5
@@ -919,17 +919,15 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)struct otp_info *buf =kmalloc (4096 ,GFP_KERNEL );if (!buf)return -ENOMEM ; - ret = -EOPNOTSUPP ;switch (mfi->mode) {case MTD_FILE_MODE_OTP_FACTORY : -if (mtd->get_fact_prot_info) - ret =mtd_get_fact_prot_info (mtd, buf,4096 ); + ret =mtd_get_fact_prot_info (mtd, buf,4096 );break ;case MTD_FILE_MODE_OTP_USER : -if (mtd->get_user_prot_info) - ret =mtd_get_user_prot_info (mtd, buf,4096 ); + ret =mtd_get_user_prot_info (mtd, buf,4096 );break ;default : + ret = -EINVAL ;break ; }if (ret >=0 ) {
include/linux/mtd/mtd.h +4 -0
@@ -342,6 +342,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,static inline int mtd_get_fact_prot_info (struct mtd_info *mtd,struct otp_info *buf,size_t len) { +if (!mtd->get_fact_prot_info) +return -EOPNOTSUPP ;return mtd->get_fact_prot_info (mtd, buf, len); }
@@ -357,6 +359,8 @@ static inline int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, size_t len) { +if (!mtd->get_user_prot_info) +return -EOPNOTSUPP ;return mtd->get_user_prot_info (mtd, buf, len); }
Signature · 1 line
1.7.7.3
PATCH 8/17 mtd: do not use mtd->read_*_prot_reg directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, call 'mtd_read_*_prot_info()' and check for -EOPNOTSUPP.
--- drivers/mtd/mtdchar.c | 18 ++++++++++-------- include/linux/mtd/mtd.h | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/mtdchar.c +10 -8
@@ -366,20 +366,22 @@ static void mtdchar_erase_callback (struct erase_info *instr)static int otp_select_filemode (struct mtd_file_info *mfi,int mode) {struct mtd_info *mtd = mfi->mtd; +size_t retlen;int ret =0 ; +/* +* Make a fake call to mtd_read_fact_prot_reg() to check if OTP +* operations are supported. +*/ +if (mtd_read_fact_prot_reg (mtd,-1 ,-1 , &retlen,NULL ) == -EOPNOTSUPP ) +return -EOPNOTSUPP ; +switch (mode) {case MTD_OTP_FACTORY : -if (!mtd->read_fact_prot_reg) - ret = -EOPNOTSUPP ; -else - mfi->mode =MTD_FILE_MODE_OTP_FACTORY ; + mfi->mode =MTD_FILE_MODE_OTP_FACTORY ;break ;case MTD_OTP_USER : -if (!mtd->read_fact_prot_reg) - ret = -EOPNOTSUPP ; -else - mfi->mode =MTD_FILE_MODE_OTP_USER ; + mfi->mode =MTD_FILE_MODE_OTP_USER ;break ;default : ret = -EINVAL ;
include/linux/mtd/mtd.h +4 -0
@@ -352,6 +352,8 @@ static inline int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, u_char *buf) { *retlen =0 ; +if (!mtd->read_fact_prot_reg) +return -EOPNOTSUPP ;return mtd->read_fact_prot_reg (mtd, from, len, retlen, buf); }
@@ -369,6 +371,8 @@ static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, u_char *buf) { *retlen =0 ; +if (!mtd->read_user_prot_reg) +return -EOPNOTSUPP ;return mtd->read_user_prot_reg (mtd, from, len, retlen, buf); }
Signature · 1 line
1.7.7.3
PATCH 9/17 mtd: mtd->write_user_prot_reg directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, just call 'mtd_write_user_prot_reg()' and check the '-EOPNOTSUPP' return code.
--- drivers/mtd/mtdchar.c | 4 ---- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/mtd/mtdchar.c +0 -4
@@ -310,10 +310,6 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c ret = -EROFS ;break ;case MTD_FILE_MODE_OTP_USER : -if (!mtd->write_user_prot_reg) { - ret = -EOPNOTSUPP ; -break ; - } ret =mtd_write_user_prot_reg (mtd, *ppos, len, &retlen, kbuf);break ;
include/linux/mtd/mtd.h +2 -0
@@ -381,6 +381,8 @@ static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, u_char *buf) { *retlen =0 ; +if (!mtd->write_user_prot_reg) +return -EOPNOTSUPP ;return mtd->write_user_prot_reg (mtd, to, len, retlen, buf); }
Signature · 1 line
1.7.7.3
PATCH 10/17 mtd: do not use mtd->lock_user_prot_reg directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, check the -EOPNOTSUPP return code of 'mtd_lock_user_prot_reg()'.
--- drivers/mtd/mtdchar.c | 2 -- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/mtdchar.c +0 -2
@@ -949,8 +949,6 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)return -EINVAL ;if (copy_from_user (&oinfo, argp,sizeof (oinfo)))return -EFAULT ; -if (!mtd->lock_user_prot_reg) -return -EOPNOTSUPP ; ret =mtd_lock_user_prot_reg (mtd, oinfo.start, oinfo.length);break ; }
include/linux/mtd/mtd.h +2 -0
@@ -389,6 +389,8 @@ static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to,static inline int mtd_lock_user_prot_reg (struct mtd_info *mtd,loff_t from,size_t len) { +if (!mtd->lock_user_prot_reg) +return -EOPNOTSUPP ;return mtd->lock_user_prot_reg (mtd, from, len); }
Signature · 1 line
1.7.7.3
PATCH 11/17 mtd: harmonize mtd_writev usage
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This patch makes the 'mtd_writev()' function more usable and logical. We first teach it to fall-back to the 'default_mtd_writev()' function if the MTD driver does not define its own '->writev()' method. Then we make block2mtd and JFFS2 just 'mtd_writev()' instead of 'default_mtd_writev()' function. This means we can now stop exporting 'default_mtd_writev()' and instead, export 'mtd_writev()'. This is much cleaner and more logical, as well as allows us to get read of another direct 'mtd->writev' access in JFFS2.
--- drivers/mtd/devices/block2mtd.c | 2 +- drivers/mtd/mtdcore.c | 26 +++++++++++++++++++++++--- fs/jffs2/writev.c | 6 +----- include/linux/mtd/mtd.h | 16 ++-------------- 4 files changed, 27 insertions(+), 23 deletions(-)
drivers/mtd/devices/block2mtd.c +1 -1
@@ -288,7 +288,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) dev->mtd.flags =MTD_CAP_RAM ; dev->mtd.erase = block2mtd_erase; dev->mtd.write = block2mtd_write; - dev->mtd.writev = default_mtd_writev; + dev->mtd.writev = mtd_writev; dev->mtd.sync = block2mtd_sync; dev->mtd.read = block2mtd_read; dev->mtd.priv = dev;
drivers/mtd/mtdcore.c +23 -3
@@ -696,8 +696,8 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);* This function returns zero in case of success and a negative error code in * case of failure. */ -int default_mtd_writev (struct mtd_info *mtd,const struct kvec *vecs, -unsigned long count,loff_t to,size_t *retlen) +static int default_mtd_writev (struct mtd_info *mtd,const struct kvec *vecs, +unsigned long count,loff_t to,size_t *retlen) {unsigned long i;size_t totlen =0 , thislen;
@@ -716,7 +716,27 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, *retlen = totlen;return ret; } -EXPORT_SYMBOL_GPL (default_mtd_writev); + +/* +* mtd_writev - the vector-based MTD write method +* @mtd: mtd device description object pointer +* @vecs: the vectors to write +* @count: count of vectors in @vecs +* @to: the MTD device offset to write to +* @retlen: on exit contains the count of bytes written to the MTD device. +* +* This function returns zero in case of success and a negative error code in +* case of failure. +*/ +int mtd_writev (struct mtd_info *mtd,const struct kvec *vecs, +unsigned long count,loff_t to,size_t *retlen) +{ + *retlen =0 ; +if (!mtd->writev) +return default_mtd_writev (mtd, vecs, count, to, retlen); +return mtd->writev (mtd, vecs, count, to, retlen); +} +EXPORT_SYMBOL_GPL (mtd_writev);/** * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size
fs/jffs2/writev.c +1 -5
@@ -26,11 +26,7 @@ int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs, } } -if (c->mtd->writev) -return mtd_writev (c->mtd, vecs, count, to, retlen); -else { -return default_mtd_writev (c->mtd, vecs, count, to, retlen); - } +return mtd_writev (c->mtd, vecs, count, to, retlen); } int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
include/linux/mtd/mtd.h +2 -14
@@ -394,16 +394,8 @@ static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,return mtd->lock_user_prot_reg (mtd, from, len); } -/* -* kvec-based read/write method. NB: The 'count' parameter is the number of -* _vectors_, each of which contains an (ofs, len) tuple. -*/ -static inline int mtd_writev (struct mtd_info *mtd,const struct kvec *vecs, -unsigned long count,loff_t to,size_t *retlen) -{ - *retlen =0 ; -return mtd->writev (mtd, vecs, count, to, retlen); -} +int mtd_writev (struct mtd_info *mtd,const struct kvec *vecs, +unsigned long count,loff_t to,size_t *retlen);static inline void mtd_sync (struct mtd_info *mtd) {
@@ -510,10 +502,6 @@ struct mtd_notifier {extern void register_mtd_user (struct mtd_notifier *new);extern int unregister_mtd_user (struct mtd_notifier *old); - -int default_mtd_writev (struct mtd_info *mtd,const struct kvec *vecs, -unsigned long count,loff_t to,size_t *retlen); -void *mtd_kmalloc_up_to (const struct mtd_info *mtd,size_t *size);void mtd_erase_callback (struct erase_info *instr);
Signature · 1 line
1.7.7.3
PATCH 12/17 mtd: do not use mtd->sync directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This patch teaches 'mtd_sync()' to do nothing when the MTD driver does not have the '->sync()' method, which allows us to remove all direct 'mtd->sync' accesses.
--- drivers/mtd/ftl.c | 3 +-- drivers/mtd/mtdblock.c | 7 ++----- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdswap.c | 3 +-- drivers/mtd/rfd_ftl.c | 3 +-- drivers/mtd/ubi/kapi.c | 4 +--- fs/jffs2/super.c | 4 +--- fs/logfs/dev_mtd.c | 3 +-- include/linux/mtd/mtd.h | 3 ++- 9 files changed, 11 insertions(+), 21 deletions(-)
drivers/mtd/ftl.c +1 -2
@@ -650,8 +650,7 @@ static int reclaim_block(partition_t *part)if (queued) {pr_debug ("ftl_cs: waiting for transfer " "unit to be prepared...\n" ); -if (part->mbd.mtd->sync) -mtd_sync (part->mbd.mtd); +mtd_sync (part->mbd.mtd); }else {static int ne =0 ;if (++ne <5 )
drivers/mtd/mtdblock.c +2 -5
@@ -322,8 +322,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)if (!--mtdblk->count) {/* It was the last usage. Free the cache */ -if (mbd->mtd->sync) -mtd_sync (mbd->mtd); +mtd_sync (mbd->mtd);vfree (mtdblk->cache_data); }
@@ -341,9 +340,7 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)mutex_lock (&mtdblk->cache_mutex);write_cached_data (mtdblk);mutex_unlock (&mtdblk->cache_mutex); - -if (dev->mtd->sync) -mtd_sync (dev->mtd); +mtd_sync (dev->mtd);return 0 ; }
drivers/mtd/mtdchar.c +1 -1
@@ -154,7 +154,7 @@ static int mtdchar_close(struct inode *inode, struct file *file)pr_debug ("MTD_close\n" );/* Only sync if opened RW */ -if ((file->f_mode &FMODE_WRITE ) && mtd->sync) +if ((file->f_mode &FMODE_WRITE ))mtd_sync (mtd);iput (mfi->ino);
drivers/mtd/mtdswap.c +1 -2
@@ -1047,8 +1047,7 @@ static int mtdswap_flush(struct mtd_blktrans_dev *dev) {struct mtdswap_dev *d =MTDSWAP_MBD_TO_MTDSWAP (dev); -if (d->mtd->sync) -mtd_sync (d->mtd); +mtd_sync (d->mtd);return 0 ; }
drivers/mtd/rfd_ftl.c +1 -2
@@ -448,8 +448,7 @@ static int reclaim_block(struct partition *part, u_long *old_sector)int rc;/* we have a race if sync doesn't exist */ -if (part->mbd.mtd->sync) -mtd_sync (part->mbd.mtd); +mtd_sync (part->mbd.mtd); score =0x7fffffff ;/* MAX_INT */ best_block =-1 ;
drivers/mtd/ubi/kapi.c +1 -3
@@ -714,9 +714,7 @@ int ubi_sync(int ubi_num)if (!ubi)return -ENODEV ; -if (ubi->mtd->sync) -mtd_sync (ubi->mtd); - +mtd_sync (ubi->mtd);ubi_put_device (ubi);return 0 ; }
fs/jffs2/super.c +1 -3
@@ -336,9 +336,7 @@ static void jffs2_put_super (struct super_block *sb)jffs2_flash_cleanup (c);kfree (c->inocache_list);jffs2_clear_xattr_subsystem (c); -if (c->mtd->sync) -mtd_sync (c->mtd); - +mtd_sync (c->mtd);D1 (printk (KERN_DEBUG "jffs2_put_super returning\n" )); }
fs/logfs/dev_mtd.c +1 -2
@@ -119,8 +119,7 @@ static void logfs_mtd_sync(struct super_block *sb) {struct mtd_info *mtd =logfs_super (sb)->s_mtd; -if (mtd->sync) -mtd_sync (mtd); +mtd_sync (mtd); }static int logfs_mtd_readpage (void *_sb,struct page *page)
include/linux/mtd/mtd.h +2 -1
@@ -399,7 +399,8 @@ int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,static inline void mtd_sync (struct mtd_info *mtd) { - mtd->sync (mtd); +if (mtd->sync) + mtd->sync (mtd); }/* Chip-supported device locking */
Signature · 1 line
1.7.7.3
PATCH 13/17 mtd: do not use mtd->lock, unlock and is_locked directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, call the corresponding MTD API function which will return '-EOPNOTSUPP' if the operation is not supported.
--- drivers/mtd/maps/scb2_flash.c | 3 +-- drivers/mtd/mtdchar.c | 15 +++------------ drivers/mtd/mtdconcat.c | 18 ++++++------------ drivers/mtd/mtdcore.c | 6 +++--- include/linux/mtd/mtd.h | 6 ++++++ 5 files changed, 19 insertions(+), 29 deletions(-)
drivers/mtd/maps/scb2_flash.c +1 -2
@@ -204,8 +204,7 @@ scb2_flash_remove(struct pci_dev *dev)return ;/* disable flash writes */ -if (scb2_mtd->lock) -mtd_lock (scb2_mtd,0 , scb2_mtd->size); +mtd_lock (scb2_mtd,0 , scb2_mtd->size);mtd_device_unregister (scb2_mtd);map_destroy (scb2_mtd);
drivers/mtd/mtdchar.c +3 -12
@@ -814,10 +814,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)if (copy_from_user (&einfo, argp,sizeof (einfo)))return -EFAULT ; -if (!mtd->lock) - ret = -EOPNOTSUPP ; -else - ret =mtd_lock (mtd, einfo.start, einfo.length); + ret =mtd_lock (mtd, einfo.start, einfo.length);break ; }
@@ -828,10 +825,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)if (copy_from_user (&einfo, argp,sizeof (einfo)))return -EFAULT ; -if (!mtd->unlock) - ret = -EOPNOTSUPP ; -else - ret =mtd_unlock (mtd, einfo.start, einfo.length); + ret =mtd_unlock (mtd, einfo.start, einfo.length);break ; }
@@ -842,10 +836,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)if (copy_from_user (&einfo, argp,sizeof (einfo)))return -EFAULT ; -if (!mtd->is_locked) - ret = -EOPNOTSUPP ; -else - ret =mtd_is_locked (mtd, einfo.start, einfo.length); + ret =mtd_is_locked (mtd, einfo.start, einfo.length);break ; }
drivers/mtd/mtdconcat.c +6 -12
@@ -555,12 +555,9 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)else size = len; -if (subdev->lock) { - err =mtd_lock (subdev, ofs, size); -if (err) -break ; - }else - err = -EOPNOTSUPP ; + err =mtd_lock (subdev, ofs, size); +if (err) +break ; len -= size;if (len ==0 )
@@ -595,12 +592,9 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)else size = len; -if (subdev->unlock) { - err =mtd_unlock (subdev, ofs, size); -if (err) -break ; - }else - err = -EOPNOTSUPP ; + err =mtd_unlock (subdev, ofs, size); +if (err) +break ; len -= size;if (len ==0 )
drivers/mtd/mtdcore.c +3 -3
@@ -339,9 +339,9 @@ int add_mtd_device(struct mtd_info *mtd) mtd->writesize_mask = (1 << mtd->writesize_shift) -1 ;/* Some chips always power up locked. Unlock them now */ -if ((mtd->flags &MTD_WRITEABLE ) - && (mtd->flags &MTD_POWERUP_LOCK ) && mtd->unlock) { -if (mtd_unlock (mtd,0 , mtd->size)) +if ((mtd->flags &MTD_WRITEABLE ) && (mtd->flags &MTD_POWERUP_LOCK )) { + error =mtd_unlock (mtd,0 , mtd->size); +if (error && error != -EOPNOTSUPP )printk (KERN_WARNING "%s: unlock failed, writes may not work\n" , mtd->name);
include/linux/mtd/mtd.h +6 -0
@@ -406,16 +406,22 @@ static inline void mtd_sync(struct mtd_info *mtd)/* Chip-supported device locking */ static inline int mtd_lock (struct mtd_info *mtd,loff_t ofs,uint64_t len) { +if (!mtd->lock) +return -EOPNOTSUPP ;return mtd->lock (mtd, ofs, len); }static inline int mtd_unlock (struct mtd_info *mtd,loff_t ofs,uint64_t len) { +if (!mtd->unlock) +return -EOPNOTSUPP ;return mtd->unlock (mtd, ofs, len); }static inline int mtd_is_locked (struct mtd_info *mtd,loff_t ofs,uint64_t len) { +if (!mtd->is_locked) +return -EOPNOTSUPP ;return mtd->is_locked (mtd, ofs, len); }
Signature · 1 line
1.7.7.3
PATCH 14/17 mtd: do not use mtd->suspend and mtd->resume directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Just call the 'mtd_suspend()' and 'mtd_resume()' - they will do nothing if the operation is not defined.
--- drivers/mtd/maps/physmap.c | 5 ++--- drivers/mtd/maps/rbtx4939-flash.c | 5 ++--- drivers/mtd/mtdcore.c | 5 +---- include/linux/mtd/mtd.h | 5 ++++- 4 files changed, 9 insertions(+), 11 deletions(-)
drivers/mtd/maps/physmap.c +2 -3
@@ -190,9 +190,8 @@ static void physmap_flash_shutdown(struct platform_device *dev)int i;for (i =0 ; i <MAX_RESOURCES && info->mtd[i]; i++) -if (info->mtd[i]->suspend && info->mtd[i]->resume) -if (mtd_suspend (info->mtd[i]) ==0 ) -mtd_resume (info->mtd[i]); +if (mtd_suspend (info->mtd[i]) ==0 ) + mtd_resume(info->mtd[i]); }#else #define physmap_flash_shutdown NULL
drivers/mtd/maps/rbtx4939-flash.c +2 -3
@@ -119,9 +119,8 @@ static void rbtx4939_flash_shutdown(struct platform_device *dev) {struct rbtx4939_flash_info *info =platform_get_drvdata (dev); -if (info->mtd->suspend && info->mtd->resume) -if (mtd_suspend (info->mtd) ==0 ) -mtd_resume (info->mtd); +if (mtd_suspend (info->mtd) ==0 ) +mtd_resume (info->mtd); }#else #define rbtx4939_flash_shutdown NULL
drivers/mtd/mtdcore.c +1 -4
@@ -119,10 +119,7 @@ static int mtd_cls_suspend(struct device *dev, pm_message_t state) {struct mtd_info *mtd =dev_get_drvdata (dev); -if (mtd && mtd->suspend) -return mtd_suspend (mtd); -else -return 0 ; +return mtd_suspend (mtd); }static int mtd_cls_resume (struct device *dev)
include/linux/mtd/mtd.h +4 -1
@@ -427,12 +427,15 @@ static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)static inline int mtd_suspend (struct mtd_info *mtd) { +if (!mtd->suspend) +return -EOPNOTSUPP ;return mtd->suspend (mtd); }static inline void mtd_resume (struct mtd_info *mtd) { - mtd->resume (mtd); +if (mtd->resume) + mtd->resume (mtd); }static inline int mtd_block_isbad (struct mtd_info *mtd,loff_t ofs)
Signature · 1 line
1.7.7.3
PATCH 15/17 mtd: introduce mtd_can_have_bb helper
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This patch introduces new 'mtd_can_have_bb()' helper function which checks whether the flash can have bad eraseblocks. Then it changes all the direct 'mtd->block_isbad' use cases with 'mtd_can_have_bb()'.
--- drivers/mtd/mtdchar.c | 5 +---- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 4 ++-- drivers/mtd/mtdswap.c | 4 ++-- drivers/mtd/nftlcore.c | 2 +- drivers/mtd/redboot.c | 4 ++-- drivers/mtd/tests/mtd_readtest.c | 3 +-- drivers/mtd/tests/mtd_speedtest.c | 3 +-- drivers/mtd/tests/mtd_stresstest.c | 3 +-- drivers/mtd/tests/mtd_torturetest.c | 2 +- drivers/mtd/ubi/build.c | 2 +- include/linux/mtd/mtd.h | 7 +++++++ 12 files changed, 21 insertions(+), 20 deletions(-)
drivers/mtd/mtdchar.c +1 -4
@@ -867,10 +867,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)if (copy_from_user (&offs, argp,sizeof (loff_t)))return -EFAULT ; -if (!mtd->block_isbad) - ret = -EOPNOTSUPP ; -else -return mtd_block_isbad (mtd, offs); +return mtd_block_isbad (mtd, offs);break ; }
drivers/mtd/mtdconcat.c +1 -1
@@ -647,7 +647,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)struct mtd_concat *concat =CONCAT (mtd);int i, res =0 ; -if (!concat->subdev[0 ]->block_isbad) +if (!mtd_can_have_bb (concat->subdev[0 ]))return res;if (ofs > mtd->size)
drivers/mtd/mtdoops.c +2 -2
@@ -169,7 +169,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work) cxt->nextpage =0 ; } -while (mtd->block_isbad) { +while (mtd_can_have_bb (mtd)) { ret =mtd_block_isbad (mtd, cxt->nextpage * record_size);if (!ret)break ;
@@ -257,7 +257,7 @@ static void find_next_position(struct mtdoops_context *cxt)size_t retlen;for (page =0 ; page < cxt->oops_pages; page++) { -if (mtd->block_isbad && +if (mtd_can_have_bb (mtd) &&mtd_block_isbad (mtd, page * record_size))continue ;/* Assume the page is used */
drivers/mtd/mtdswap.c +2 -2
@@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb) offset =mtdswap_eb_offset (d, eb);/* Check first if the block is bad. */ -if (d->mtd->block_isbad &&mtd_block_isbad (d->mtd, offset)) +if (mtd_can_have_bb (d->mtd) &&mtd_block_isbad (d->mtd, offset))return MTDSWAP_SCANNED_BAD ; ops.ooblen =2 * d->mtd->ecclayout->oobavail;
@@ -1058,7 +1058,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size) badcnt =0 ; -if (mtd->block_isbad) +if (mtd_can_have_bb (mtd))for (offset =0 ; offset < size; offset += mtd->erasesize)if (mtd_block_isbad (mtd, offset)) badcnt++;
drivers/mtd/nftlcore.c +1 -1
@@ -56,7 +56,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)if (memcmp (mtd->name,"DiskOnChip" ,10 ))return ; -if (!mtd->block_isbad) { +if (!mtd_can_have_bb (mtd)) {printk (KERN_ERR "NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n" "Please use the new diskonchip driver under the NAND subsystem.\n" );
drivers/mtd/redboot.c +2 -2
@@ -78,7 +78,7 @@ static int parse_redboot_partitions(struct mtd_info *master,if ( directory <0 ) { offset = master->size + directory * master->erasesize; -while (master->block_isbad && +while (mtd_can_have_bb (master) &&mtd_block_isbad (master, offset)) {if (!offset) { nogood:
@@ -89,7 +89,7 @@ static int parse_redboot_partitions(struct mtd_info *master, } }else { offset = directory * master->erasesize; -while (master->block_isbad && +while (mtd_can_have_bb (master) &&mtd_block_isbad (master, offset)) { offset += master->erasesize;if (offset == master->size)
drivers/mtd/tests/mtd_readtest.c +1 -2
@@ -148,8 +148,7 @@ static int scan_for_bad_eraseblocks(void)return -ENOMEM ; } -/* NOR flash does not implement block_isbad */ -if (mtd->block_isbad ==NULL ) +if (!mtd_can_have_bb (mtd))return 0 ;printk (PRINT_PREF "scanning for bad eraseblocks\n" );
drivers/mtd/tests/mtd_speedtest.c +1 -2
@@ -336,8 +336,7 @@ static int scan_for_bad_eraseblocks(void)return -ENOMEM ; } -/* NOR flash does not implement block_isbad */ -if (mtd->block_isbad ==NULL ) +if (!mtd_can_have_bb (mtd)) goto out;printk (PRINT_PREF "scanning for bad eraseblocks\n" );
drivers/mtd/tests/mtd_stresstest.c +1 -2
@@ -227,8 +227,7 @@ static int scan_for_bad_eraseblocks(void)return -ENOMEM ; } -/* NOR flash does not implement block_isbad */ -if (mtd->block_isbad ==NULL ) +if (!mtd_can_have_bb (mtd))return 0 ;printk (PRINT_PREF "scanning for bad eraseblocks\n" );
drivers/mtd/tests/mtd_torturetest.c +1 -1
@@ -290,7 +290,7 @@ static int __init tort_init(void)* Check if there is a bad eraseblock among those we are going to test. */ memset (&bad_ebs[0 ],0 ,sizeof (int ) * ebcnt); -if (mtd->block_isbad) { +if (mtd_can_have_bb (mtd)) {for (i = eb; i < eb + ebcnt; i++) { err =mtd_block_isbad (mtd, (loff_t )i * mtd->erasesize);
drivers/mtd/ubi/build.c +1 -1
@@ -664,7 +664,7 @@ static int io_init(struct ubi_device *ubi) ubi->peb_count =mtd_div_by_eb (ubi->mtd->size, ubi->mtd); ubi->flash_size = ubi->mtd->size; -if (ubi->mtd->block_isbad && ubi->mtd->block_markbad) +if (mtd_can_have_bb (ubi->mtd)) ubi->bad_allowed =1 ;if (ubi->mtd->type ==MTD_NORFLASH ) {
include/linux/mtd/mtd.h +7 -0
@@ -440,6 +440,8 @@ static inline void mtd_resume(struct mtd_info *mtd)static inline int mtd_block_isbad (struct mtd_info *mtd,loff_t ofs) { +if (!mtd->block_isbad) +return -EOPNOTSUPP ;return mtd->block_isbad (mtd, ofs); }
@@ -483,6 +485,11 @@ static inline int mtd_has_oob(const struct mtd_info *mtd)return mtd->read_oob && mtd->write_oob; } +static inline int mtd_can_have_bb (const struct mtd_info *mtd) +{ +return !!mtd->block_isbad; +} +/* Kernel-side ioctl definitions */ struct mtd_partition ;
Signature · 1 line
1.7.7.3
PATCH 16/17 logfs: do not use 'mtd->block_isbad' directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, use the new 'mtd_can_have_bb()' helper.
--- fs/logfs/dev_mtd.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/logfs/dev_mtd.c +2 -2
@@ -152,7 +152,7 @@ static struct page *logfs_mtd_find_first_sb(struct super_block *sb, u64 *ofs)filler_t *filler = logfs_mtd_readpage;struct mtd_info *mtd = super->s_mtd; -if (!mtd->block_isbad) +if (!mtd_can_have_bb (mtd))return NULL ; *ofs =0 ;
@@ -172,7 +172,7 @@ static struct page *logfs_mtd_find_last_sb(struct super_block *sb, u64 *ofs)filler_t *filler = logfs_mtd_readpage;struct mtd_info *mtd = super->s_mtd; -if (!mtd->block_isbad) +if (!mtd_can_have_bb (mtd))return NULL ; *ofs = mtd->size - mtd->erasesize;
Signature · 1 line
1.7.7.3
PATCH 17/17 mtd: do not use mtd->block_markbad directly
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead, use the new 'mtd_can_have_bb()', or just rely on 'mtd_block_markbad()' return code, which will be -EOPNOTSUPP if bad blocks are not supported.
--- drivers/mtd/mtdchar.c | 5 +---- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 2 +- drivers/mtd/mtdswap.c | 2 +- fs/jffs2/wbuf.c | 3 --- include/linux/mtd/mtd.h | 2 ++ 6 files changed, 6 insertions(+), 10 deletions(-)
drivers/mtd/mtdchar.c +1 -4
@@ -877,10 +877,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)if (copy_from_user (&offs, argp,sizeof (loff_t)))return -EFAULT ; -if (!mtd->block_markbad) - ret = -EOPNOTSUPP ; -else -return mtd_block_markbad (mtd, offs); +return mtd_block_markbad (mtd, offs);break ; }
drivers/mtd/mtdconcat.c +1 -1
@@ -673,7 +673,7 @@ static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)struct mtd_concat *concat =CONCAT (mtd);int i, err = -EINVAL ; -if (!concat->subdev[0 ]->block_markbad) +if (!mtd_can_have_bb (concat->subdev[0 ]))return 0 ;if (ofs > mtd->size)
drivers/mtd/mtdoops.c +1 -1
@@ -199,7 +199,7 @@ badblock:return ; } -if (mtd->block_markbad && ret == -EIO ) { +if (mtd_can_have_bb (mtd) && ret == -EIO ) { ret =mtd_block_markbad (mtd, cxt->nextpage * record_size);if (ret <0 ) {printk (KERN_ERR "mtdoops: block_markbad failed, aborting\n" );
drivers/mtd/mtdswap.c +1 -1
@@ -274,7 +274,7 @@ static int mtdswap_handle_badblock(struct mtdswap_dev *d, struct swap_eb *eb) eb->root =NULL ;/* badblocks not supported */ -if (!d->mtd->block_markbad) +if (!mtd_can_have_bb (d->mtd))return 1 ; offset =mtdswap_eb_offset (d, eb);
fs/jffs2/wbuf.c +0 -3
@@ -1130,9 +1130,6 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *if ( ++jeb->bad_count <MAX_ERASE_FAILURES )return 0 ; -if (!c->mtd->block_markbad) -return 1 ;// What else can we do? -printk (KERN_WARNING "JFFS2: marking eraseblock at %08x\n as bad" , bad_offset); ret =mtd_block_markbad (c->mtd, bad_offset);
include/linux/mtd/mtd.h +2 -0
@@ -447,6 +447,8 @@ static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)static inline int mtd_block_markbad (struct mtd_info *mtd,loff_t ofs) { +if (!mtd->block_markbad) +return -EOPNOTSUPP ;return mtd->block_markbad (mtd, ofs); }
Signature · 1 line
1.7.7.3