Commit 5e4e6e3fdf48c1b012e2b6e80ed1d7e99d4fa6d1

Authored by Artem Bityutskiy
Committed by David Woodhouse
1 parent e2414f4c20

mtd: return error code from mtd_unpoint

The 'mtd_unpoint()' API function should be able to return an error code because
it may fail if you specify incorrect offset. This patch changes this MTD API
function and amends all the drivers correspondingly.

Also return '-EOPNOTSUPP' from 'mtd_unpoint()' when the '->unpoint()' method is
undefined. We do not really need this currently, but this just makes
sense to be consistent with 'mtd_point()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Showing 9 changed files with 33 additions and 20 deletions Side-by-side Diff

drivers/mtd/chips/cfi_cmdset_0001.c
... ... @@ -87,7 +87,7 @@
87 87  
88 88 static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len,
89 89 size_t *retlen, void **virt, resource_size_t *phys);
90   -static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
  90 +static int cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
91 91  
92 92 static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
93 93 static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
94 94  
... ... @@ -1369,12 +1369,12 @@
1369 1369 return 0;
1370 1370 }
1371 1371  
1372   -static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  1372 +static int cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
1373 1373 {
1374 1374 struct map_info *map = mtd->priv;
1375 1375 struct cfi_private *cfi = map->fldrv_priv;
1376 1376 unsigned long ofs;
1377   - int chipnum;
  1377 + int chipnum, err = 0;
1378 1378  
1379 1379 /* Now unlock the chip(s) POINT state */
1380 1380  
... ... @@ -1382,7 +1382,7 @@
1382 1382 chipnum = (from >> cfi->chipshift);
1383 1383 ofs = from - (chipnum << cfi->chipshift);
1384 1384  
1385   - while (len) {
  1385 + while (len && !err) {
1386 1386 unsigned long thislen;
1387 1387 struct flchip *chip;
1388 1388  
... ... @@ -1400,8 +1400,10 @@
1400 1400 chip->ref_point_counter--;
1401 1401 if(chip->ref_point_counter == 0)
1402 1402 chip->state = FL_READY;
1403   - } else
1404   - printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */
  1403 + } else {
  1404 + printk(KERN_ERR "%s: Error: unpoint called on non pointed region\n", map->name);
  1405 + err = -EINVAL;
  1406 + }
1405 1407  
1406 1408 put_chip(map, chip, chip->start);
1407 1409 mutex_unlock(&chip->mutex);
... ... @@ -1410,6 +1412,8 @@
1410 1412 ofs = 0;
1411 1413 chipnum++;
1412 1414 }
  1415 +
  1416 + return err;
1413 1417 }
1414 1418  
1415 1419 static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf)
drivers/mtd/devices/mtdram.c
... ... @@ -60,8 +60,9 @@
60 60 return 0;
61 61 }
62 62  
63   -static void ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  63 +static int ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
64 64 {
  65 + return 0;
65 66 }
66 67  
67 68 /*
drivers/mtd/devices/phram.c
... ... @@ -70,8 +70,9 @@
70 70 return 0;
71 71 }
72 72  
73   -static void phram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  73 +static int phram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
74 74 {
  75 + return 0;
75 76 }
76 77  
77 78 static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
drivers/mtd/devices/pmc551.c
... ... @@ -206,11 +206,12 @@
206 206 return 0;
207 207 }
208 208  
209   -static void pmc551_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  209 +static int pmc551_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
210 210 {
211 211 #ifdef CONFIG_MTD_PMC551_DEBUG
212 212 printk(KERN_DEBUG "pmc551_unpoint()\n");
213 213 #endif
  214 + return 0;
214 215 }
215 216  
216 217 static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
drivers/mtd/devices/slram.c
... ... @@ -76,7 +76,7 @@
76 76 static int slram_erase(struct mtd_info *, struct erase_info *);
77 77 static int slram_point(struct mtd_info *, loff_t, size_t, size_t *, void **,
78 78 resource_size_t *);
79   -static void slram_unpoint(struct mtd_info *, loff_t, size_t);
  79 +static int slram_unpoint(struct mtd_info *, loff_t, size_t);
80 80 static int slram_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
81 81 static int slram_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
82 82  
83 83  
... ... @@ -119,8 +119,9 @@
119 119 return(0);
120 120 }
121 121  
122   -static void slram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  122 +static int slram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
123 123 {
  124 + return 0;
124 125 }
125 126  
126 127 static int slram_read(struct mtd_info *mtd, loff_t from, size_t len,
drivers/mtd/lpddr/lpddr_cmds.c
... ... @@ -40,7 +40,7 @@
40 40 static int lpddr_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
41 41 static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
42 42 size_t *retlen, void **mtdbuf, resource_size_t *phys);
43   -static void lpddr_unpoint(struct mtd_info *mtd, loff_t adr, size_t len);
  43 +static int lpddr_unpoint(struct mtd_info *mtd, loff_t adr, size_t len);
44 44 static int get_chip(struct map_info *map, struct flchip *chip, int mode);
45 45 static int chip_ready(struct map_info *map, struct flchip *chip, int mode);
46 46 static void put_chip(struct map_info *map, struct flchip *chip);
47 47  
... ... @@ -575,11 +575,11 @@
575 575 return 0;
576 576 }
577 577  
578   -static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
  578 +static int lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
579 579 {
580 580 struct map_info *map = mtd->priv;
581 581 struct lpddr_private *lpddr = map->fldrv_priv;
582   - int chipnum = adr >> lpddr->chipshift;
  582 + int chipnum = adr >> lpddr->chipshift, err = 0;
583 583 unsigned long ofs;
584 584  
585 585 /* ofs: offset within the first chip that the first read should start */
586 586  
... ... @@ -603,9 +603,11 @@
603 603 chip->ref_point_counter--;
604 604 if (chip->ref_point_counter == 0)
605 605 chip->state = FL_READY;
606   - } else
  606 + } else {
607 607 printk(KERN_WARNING "%s: Warning: unpoint called on non"
608 608 "pointed region\n", map->name);
  609 + err = -EINVAL;
  610 + }
609 611  
610 612 put_chip(map, chip);
611 613 mutex_unlock(&chip->mutex);
... ... @@ -614,6 +616,8 @@
614 616 ofs = 0;
615 617 chipnum++;
616 618 }
  619 +
  620 + return err;
617 621 }
618 622  
619 623 static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
drivers/mtd/mtdpart.c
... ... @@ -92,11 +92,11 @@
92 92 virt, phys);
93 93 }
94 94  
95   -static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  95 +static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
96 96 {
97 97 struct mtd_part *part = PART(mtd);
98 98  
99   - mtd_unpoint(part->master, from + part->offset, len);
  99 + return mtd_unpoint(part->master, from + part->offset, len);
100 100 }
101 101  
102 102 static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
include/linux/mtd/mtd.h
... ... @@ -177,7 +177,7 @@
177 177 int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
178 178 int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
179 179 size_t *retlen, void **virt, resource_size_t *phys);
180   - void (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
  180 + int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
181 181 unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
182 182 unsigned long len,
183 183 unsigned long offset,
184 184  
... ... @@ -265,8 +265,10 @@
265 265 }
266 266  
267 267 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
268   -static inline void mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  268 +static inline int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
269 269 {
  270 + if (!mtd->_point)
  271 + return -EOPNOTSUPP;
270 272 return mtd->_unpoint(mtd, from, len);
271 273 }
272 274  
include/linux/mtd/pmc551.h
... ... @@ -34,7 +34,6 @@
34 34 * Function Prototypes
35 35 */
36 36 static int pmc551_erase(struct mtd_info *, struct erase_info *);
37   -static void pmc551_unpoint(struct mtd_info *, loff_t, size_t);
38 37 static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
39 38 size_t *retlen, void **virt, resource_size_t *phys);
40 39 static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);