aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/mtdcore.c41
-rw-r--r--include/linux/mtd/mtd.h2
2 files changed, 24 insertions, 19 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 8bea2d0fdb20..85a3f197e7f0 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -683,10 +683,17 @@ void __put_mtd_device(struct mtd_info *mtd)
683 module_put(mtd->owner); 683 module_put(mtd->owner);
684} 684}
685 685
686/* default_mtd_writev - default mtd writev method for MTD devices that 686/*
687 * don't implement their own 687 * default_mtd_writev - the default writev method
688 * @mtd: mtd device description object pointer
689 * @vecs: the vectors to write
690 * @count: count of vectors in @vecs
691 * @to: the MTD device offset to write to
692 * @retlen: on exit contains the count of bytes written to the MTD device.
693 *
694 * This function returns zero in case of success and a negative error code in
695 * case of failure.
688 */ 696 */
689
690int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, 697int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
691 unsigned long count, loff_t to, size_t *retlen) 698 unsigned long count, loff_t to, size_t *retlen)
692{ 699{
@@ -694,28 +701,24 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
694 size_t totlen = 0, thislen; 701 size_t totlen = 0, thislen;
695 int ret = 0; 702 int ret = 0;
696 703
697 if(!mtd->write) { 704 for (i = 0; i < count; i++) {
698 ret = -EROFS; 705 if (!vecs[i].iov_len)
699 } else { 706 continue;
700 for (i=0; i<count; i++) { 707 ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen,
701 if (!vecs[i].iov_len) 708 vecs[i].iov_base);
702 continue; 709 totlen += thislen;
703 ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen, 710 if (ret || thislen != vecs[i].iov_len)
704 vecs[i].iov_base); 711 break;
705 totlen += thislen; 712 to += vecs[i].iov_len;
706 if (ret || thislen != vecs[i].iov_len)
707 break;
708 to += vecs[i].iov_len;
709 }
710 } 713 }
711 if (retlen) 714 *retlen = totlen;
712 *retlen = totlen;
713 return ret; 715 return ret;
714} 716}
715 717
716/** 718/**
717 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size 719 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size
718 * @size: A pointer to the ideal or maximum size of the allocation. Points 720 * @mtd: mtd device description object pointer
721 * @size: a pointer to the ideal or maximum size of the allocation, points
719 * to the actual allocation size on success. 722 * to the actual allocation size on success.
720 * 723 *
721 * This routine attempts to allocate a contiguous kernel buffer up to 724 * This routine attempts to allocate a contiguous kernel buffer up to
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 671c89289fc3..f0dd5a305b89 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -291,6 +291,8 @@ static inline int mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
291 size_t *retlen, const u_char *buf) 291 size_t *retlen, const u_char *buf)
292{ 292{
293 *retlen = 0; 293 *retlen = 0;
294 if (!mtd->write)
295 return -EROFS;
294 return mtd->write(mtd, to, len, retlen, buf); 296 return mtd->write(mtd, to, len, retlen, buf);
295} 297}
296 298