Skip to content

Commit 1dbebd3

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: harmonize mtd_writev usage
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. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent e2936b2 commit 1dbebd3

4 files changed

Lines changed: 27 additions & 23 deletions

File tree

‎drivers/mtd/devices/block2mtd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
288288
dev->mtd.flags = MTD_CAP_RAM;
289289
dev->mtd.erase = block2mtd_erase;
290290
dev->mtd.write = block2mtd_write;
291-
dev->mtd.writev = default_mtd_writev;
291+
dev->mtd.writev = mtd_writev;
292292
dev->mtd.sync = block2mtd_sync;
293293
dev->mtd.read = block2mtd_read;
294294
dev->mtd.priv = dev;

‎drivers/mtd/mtdcore.c‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,8 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);
696696
* This function returns zero in case of success and a negative error code in
697697
* case of failure.
698698
*/
699-
int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
700-
unsigned long count, loff_t to, size_t *retlen)
699+
static int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
700+
unsigned long count, loff_t to, size_t *retlen)
701701
{
702702
unsigned long i;
703703
size_t totlen = 0, thislen;
@@ -716,7 +716,27 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
716716
*retlen = totlen;
717717
return ret;
718718
}
719-
EXPORT_SYMBOL_GPL(default_mtd_writev);
719+
720+
/*
721+
* mtd_writev - the vector-based MTD write method
722+
* @mtd: mtd device description object pointer
723+
* @vecs: the vectors to write
724+
* @count: count of vectors in @vecs
725+
* @to: the MTD device offset to write to
726+
* @retlen: on exit contains the count of bytes written to the MTD device.
727+
*
728+
* This function returns zero in case of success and a negative error code in
729+
* case of failure.
730+
*/
731+
int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
732+
unsigned long count, loff_t to, size_t *retlen)
733+
{
734+
*retlen = 0;
735+
if (!mtd->writev)
736+
return default_mtd_writev(mtd, vecs, count, to, retlen);
737+
return mtd->writev(mtd, vecs, count, to, retlen);
738+
}
739+
EXPORT_SYMBOL_GPL(mtd_writev);
720740

721741
/**
722742
* mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size

‎fs/jffs2/writev.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
2626
}
2727
}
2828

29-
if (c->mtd->writev)
30-
return mtd_writev(c->mtd, vecs, count, to, retlen);
31-
else {
32-
return default_mtd_writev(c->mtd, vecs, count, to, retlen);
33-
}
29+
return mtd_writev(c->mtd, vecs, count, to, retlen);
3430
}
3531

3632
int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,

‎include/linux/mtd/mtd.h‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,8 @@ static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
394394
return mtd->lock_user_prot_reg(mtd, from, len);
395395
}
396396

397-
/*
398-
* kvec-based read/write method. NB: The 'count' parameter is the number of
399-
* _vectors_, each of which contains an (ofs, len) tuple.
400-
*/
401-
static inline int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
402-
unsigned long count, loff_t to, size_t *retlen)
403-
{
404-
*retlen = 0;
405-
return mtd->writev(mtd, vecs, count, to, retlen);
406-
}
397+
int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
398+
unsigned long count, loff_t to, size_t *retlen);
407399

408400
static inline void mtd_sync(struct mtd_info *mtd)
409401
{
@@ -510,10 +502,6 @@ struct mtd_notifier {
510502

511503
extern void register_mtd_user (struct mtd_notifier *new);
512504
extern int unregister_mtd_user (struct mtd_notifier *old);
513-
514-
int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
515-
unsigned long count, loff_t to, size_t *retlen);
516-
517505
void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
518506

519507
void mtd_erase_callback(struct erase_info *instr);

0 commit comments

Comments
 (0)