Commit 5e4e6e3f authored by Artem Bityutskiy's avatar Artem Bityutskiy Committed by David Woodhouse

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: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent e2414f4c
...@@ -87,7 +87,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *, struct cfi_private ** ...@@ -87,7 +87,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *, struct cfi_private **
static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, void **virt, resource_size_t *phys); size_t *retlen, void **virt, resource_size_t *phys);
static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len); static int cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long adr, int mode); static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode); static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
...@@ -1369,12 +1369,12 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1369,12 +1369,12 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
return 0; return 0;
} }
static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static int cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
struct map_info *map = mtd->priv; struct map_info *map = mtd->priv;
struct cfi_private *cfi = map->fldrv_priv; struct cfi_private *cfi = map->fldrv_priv;
unsigned long ofs; unsigned long ofs;
int chipnum; int chipnum, err = 0;
/* Now unlock the chip(s) POINT state */ /* Now unlock the chip(s) POINT state */
...@@ -1382,7 +1382,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len) ...@@ -1382,7 +1382,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
chipnum = (from >> cfi->chipshift); chipnum = (from >> cfi->chipshift);
ofs = from - (chipnum << cfi->chipshift); ofs = from - (chipnum << cfi->chipshift);
while (len) { while (len && !err) {
unsigned long thislen; unsigned long thislen;
struct flchip *chip; struct flchip *chip;
...@@ -1400,8 +1400,10 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len) ...@@ -1400,8 +1400,10 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
chip->ref_point_counter--; chip->ref_point_counter--;
if(chip->ref_point_counter == 0) if(chip->ref_point_counter == 0)
chip->state = FL_READY; chip->state = FL_READY;
} else } else {
printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */ printk(KERN_ERR "%s: Error: unpoint called on non pointed region\n", map->name);
err = -EINVAL;
}
put_chip(map, chip, chip->start); put_chip(map, chip, chip->start);
mutex_unlock(&chip->mutex); mutex_unlock(&chip->mutex);
...@@ -1410,6 +1412,8 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len) ...@@ -1410,6 +1412,8 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
ofs = 0; ofs = 0;
chipnum++; chipnum++;
} }
return err;
} }
static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf) static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf)
......
...@@ -60,8 +60,9 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -60,8 +60,9 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
return 0; return 0;
} }
static void ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static int ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
return 0;
} }
/* /*
......
...@@ -70,8 +70,9 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -70,8 +70,9 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
return 0; return 0;
} }
static void phram_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static int phram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
return 0;
} }
static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
......
...@@ -206,11 +206,12 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -206,11 +206,12 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
return 0; return 0;
} }
static void pmc551_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static int pmc551_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
#ifdef CONFIG_MTD_PMC551_DEBUG #ifdef CONFIG_MTD_PMC551_DEBUG
printk(KERN_DEBUG "pmc551_unpoint()\n"); printk(KERN_DEBUG "pmc551_unpoint()\n");
#endif #endif
return 0;
} }
static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len, static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
......
...@@ -76,7 +76,7 @@ static slram_mtd_list_t *slram_mtdlist = NULL; ...@@ -76,7 +76,7 @@ static slram_mtd_list_t *slram_mtdlist = NULL;
static int slram_erase(struct mtd_info *, struct erase_info *); static int slram_erase(struct mtd_info *, struct erase_info *);
static int slram_point(struct mtd_info *, loff_t, size_t, size_t *, void **, static int slram_point(struct mtd_info *, loff_t, size_t, size_t *, void **,
resource_size_t *); resource_size_t *);
static void slram_unpoint(struct mtd_info *, loff_t, size_t); static int slram_unpoint(struct mtd_info *, loff_t, size_t);
static int slram_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int slram_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
static int slram_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); static int slram_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
...@@ -119,8 +119,9 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -119,8 +119,9 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
return(0); return(0);
} }
static void slram_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static int slram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
return 0;
} }
static int slram_read(struct mtd_info *mtd, loff_t from, size_t len, static int slram_read(struct mtd_info *mtd, loff_t from, size_t len,
......
...@@ -40,7 +40,7 @@ static int lpddr_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len); ...@@ -40,7 +40,7 @@ static int lpddr_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
static int lpddr_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); static int lpddr_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
size_t *retlen, void **mtdbuf, resource_size_t *phys); size_t *retlen, void **mtdbuf, resource_size_t *phys);
static void lpddr_unpoint(struct mtd_info *mtd, loff_t adr, size_t len); static int lpddr_unpoint(struct mtd_info *mtd, loff_t adr, size_t len);
static int get_chip(struct map_info *map, struct flchip *chip, int mode); static int get_chip(struct map_info *map, struct flchip *chip, int mode);
static int chip_ready(struct map_info *map, struct flchip *chip, int mode); static int chip_ready(struct map_info *map, struct flchip *chip, int mode);
static void put_chip(struct map_info *map, struct flchip *chip); static void put_chip(struct map_info *map, struct flchip *chip);
...@@ -575,11 +575,11 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, ...@@ -575,11 +575,11 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
return 0; return 0;
} }
static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) static int lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
{ {
struct map_info *map = mtd->priv; struct map_info *map = mtd->priv;
struct lpddr_private *lpddr = map->fldrv_priv; struct lpddr_private *lpddr = map->fldrv_priv;
int chipnum = adr >> lpddr->chipshift; int chipnum = adr >> lpddr->chipshift, err = 0;
unsigned long ofs; unsigned long ofs;
/* ofs: offset within the first chip that the first read should start */ /* ofs: offset within the first chip that the first read should start */
...@@ -603,9 +603,11 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) ...@@ -603,9 +603,11 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
chip->ref_point_counter--; chip->ref_point_counter--;
if (chip->ref_point_counter == 0) if (chip->ref_point_counter == 0)
chip->state = FL_READY; chip->state = FL_READY;
} else } else {
printk(KERN_WARNING "%s: Warning: unpoint called on non" printk(KERN_WARNING "%s: Warning: unpoint called on non"
"pointed region\n", map->name); "pointed region\n", map->name);
err = -EINVAL;
}
put_chip(map, chip); put_chip(map, chip);
mutex_unlock(&chip->mutex); mutex_unlock(&chip->mutex);
...@@ -614,6 +616,8 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len) ...@@ -614,6 +616,8 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
ofs = 0; ofs = 0;
chipnum++; chipnum++;
} }
return err;
} }
static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len, static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
......
...@@ -92,11 +92,11 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -92,11 +92,11 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
virt, phys); virt, phys);
} }
static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
mtd_unpoint(part->master, from + part->offset, len); return mtd_unpoint(part->master, from + part->offset, len);
} }
static unsigned long part_get_unmapped_area(struct mtd_info *mtd, static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
......
...@@ -177,7 +177,7 @@ struct mtd_info { ...@@ -177,7 +177,7 @@ struct mtd_info {
int (*_erase) (struct mtd_info *mtd, struct erase_info *instr); int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
int (*_point) (struct mtd_info *mtd, loff_t from, size_t len, int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, void **virt, resource_size_t *phys); size_t *retlen, void **virt, resource_size_t *phys);
void (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len); int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
unsigned long (*_get_unmapped_area) (struct mtd_info *mtd, unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
unsigned long len, unsigned long len,
unsigned long offset, unsigned long offset,
...@@ -265,8 +265,10 @@ static inline int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -265,8 +265,10 @@ static inline int mtd_point(struct mtd_info *mtd, loff_t from, size_t len,
} }
/* We probably shouldn't allow XIP if the unpoint isn't a NULL */ /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
static inline void mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len) static inline int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{ {
if (!mtd->_point)
return -EOPNOTSUPP;
return mtd->_unpoint(mtd, from, len); return mtd->_unpoint(mtd, from, len);
} }
......
...@@ -34,7 +34,6 @@ struct mypriv { ...@@ -34,7 +34,6 @@ struct mypriv {
* Function Prototypes * Function Prototypes
*/ */
static int pmc551_erase(struct mtd_info *, struct erase_info *); static int pmc551_erase(struct mtd_info *, struct erase_info *);
static void pmc551_unpoint(struct mtd_info *, loff_t, size_t);
static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len, static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, void **virt, resource_size_t *phys); size_t *retlen, void **virt, resource_size_t *phys);
static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment