Skip to content

Commit

Permalink
mtd: return error code from mtd_unpoint
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Artem Bityutskiy authored and David Woodhouse committed Mar 26, 2012
1 parent e2414f4 commit 5e4e6e3
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 20 deletions.
16 changes: 10 additions & 6 deletions drivers/mtd/chips/cfi_cmdset_0001.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
Expand Down Expand Up @@ -1369,20 +1369,20 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
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 cfi_private *cfi = map->fldrv_priv;
unsigned long ofs;
int chipnum;
int chipnum, err = 0;

/* Now unlock the chip(s) POINT state */

/* ofs: offset within the first chip that the first read should start */
chipnum = (from >> cfi->chipshift);
ofs = from - (chipnum << cfi->chipshift);

while (len) {
while (len && !err) {
unsigned long thislen;
struct flchip *chip;

Expand All @@ -1400,8 +1400,10 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
chip->ref_point_counter--;
if(chip->ref_point_counter == 0)
chip->state = FL_READY;
} else
printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */
} else {
printk(KERN_ERR "%s: Error: unpoint called on non pointed region\n", map->name);
err = -EINVAL;
}

put_chip(map, chip, chip->start);
mutex_unlock(&chip->mutex);
Expand All @@ -1410,6 +1412,8 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
ofs = 0;
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)
Expand Down
3 changes: 2 additions & 1 deletion drivers/mtd/devices/mtdram.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
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;
}

/*
Expand Down
3 changes: 2 additions & 1 deletion drivers/mtd/devices/phram.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
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,
Expand Down
3 changes: 2 additions & 1 deletion drivers/mtd/devices/pmc551.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
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
printk(KERN_DEBUG "pmc551_unpoint()\n");
#endif
return 0;
}

static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
Expand Down
5 changes: 3 additions & 2 deletions drivers/mtd/devices/slram.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_point(struct mtd_info *, loff_t, size_t, size_t *, void **,
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_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);

Expand Down Expand Up @@ -119,8 +119,9 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
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,
Expand Down
12 changes: 8 additions & 4 deletions drivers/mtd/lpddr/lpddr_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_point(struct mtd_info *mtd, loff_t adr, size_t len,
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 chip_ready(struct map_info *map, struct flchip *chip, int mode);
static void put_chip(struct map_info *map, struct flchip *chip);
Expand Down Expand Up @@ -575,11 +575,11 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
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 lpddr_private *lpddr = map->fldrv_priv;
int chipnum = adr >> lpddr->chipshift;
int chipnum = adr >> lpddr->chipshift, err = 0;
unsigned long ofs;

/* ofs: offset within the first chip that the first read should start */
Expand All @@ -603,9 +603,11 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
chip->ref_point_counter--;
if (chip->ref_point_counter == 0)
chip->state = FL_READY;
} else
} else {
printk(KERN_WARNING "%s: Warning: unpoint called on non"
"pointed region\n", map->name);
err = -EINVAL;
}

put_chip(map, chip);
mutex_unlock(&chip->mutex);
Expand All @@ -614,6 +616,8 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
ofs = 0;
chipnum++;
}

return err;
}

static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/mtdpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
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);

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,
Expand Down
6 changes: 4 additions & 2 deletions include/linux/mtd/mtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct mtd_info {
int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
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 len,
unsigned long offset,
Expand Down Expand Up @@ -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 */
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);
}

Expand Down
1 change: 0 additions & 1 deletion include/linux/mtd/pmc551.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct mypriv {
* Function Prototypes
*/
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,
size_t *retlen, void **virt, resource_size_t *phys);
static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
Expand Down

0 comments on commit 5e4e6e3

Please sign in to comment.