Skip to content

Commit 5e4e6e3

Browse files
dedekindDavid Woodhouse
authored andcommitted
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>
1 parent e2414f4 commit 5e4e6e3

9 files changed

Lines changed: 33 additions & 20 deletions

File tree

drivers/mtd/chips/cfi_cmdset_0001.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *, struct cfi_private **
8787

8888
static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len,
8989
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);
9191

9292
static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
9393
static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
@@ -1369,20 +1369,20 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
13691369
return 0;
13701370
}
13711371

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)
13731373
{
13741374
struct map_info *map = mtd->priv;
13751375
struct cfi_private *cfi = map->fldrv_priv;
13761376
unsigned long ofs;
1377-
int chipnum;
1377+
int chipnum, err = 0;
13781378

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

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

1385-
while (len) {
1385+
while (len && !err) {
13861386
unsigned long thislen;
13871387
struct flchip *chip;
13881388

@@ -1400,8 +1400,10 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
14001400
chip->ref_point_counter--;
14011401
if(chip->ref_point_counter == 0)
14021402
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+
}
14051407

14061408
put_chip(map, chip, chip->start);
14071409
mutex_unlock(&chip->mutex);
@@ -1410,6 +1412,8 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
14101412
ofs = 0;
14111413
chipnum++;
14121414
}
1415+
1416+
return err;
14131417
}
14141418

14151419
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
6060
return 0;
6161
}
6262

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)
6464
{
65+
return 0;
6566
}
6667

6768
/*

drivers/mtd/devices/phram.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
7070
return 0;
7171
}
7272

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)
7474
{
75+
return 0;
7576
}
7677

7778
static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,

drivers/mtd/devices/pmc551.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
206206
return 0;
207207
}
208208

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)
210210
{
211211
#ifdef CONFIG_MTD_PMC551_DEBUG
212212
printk(KERN_DEBUG "pmc551_unpoint()\n");
213213
#endif
214+
return 0;
214215
}
215216

216217
static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,

drivers/mtd/devices/slram.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static slram_mtd_list_t *slram_mtdlist = NULL;
7676
static int slram_erase(struct mtd_info *, struct erase_info *);
7777
static int slram_point(struct mtd_info *, loff_t, size_t, size_t *, void **,
7878
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);
8080
static int slram_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
8181
static int slram_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
8282

@@ -119,8 +119,9 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
119119
return(0);
120120
}
121121

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)
123123
{
124+
return 0;
124125
}
125126

126127
static int slram_read(struct mtd_info *mtd, loff_t from, size_t len,

drivers/mtd/lpddr/lpddr_cmds.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int lpddr_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
4040
static int lpddr_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
4141
static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
4242
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);
4444
static int get_chip(struct map_info *map, struct flchip *chip, int mode);
4545
static int chip_ready(struct map_info *map, struct flchip *chip, int mode);
4646
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,
575575
return 0;
576576
}
577577

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)
579579
{
580580
struct map_info *map = mtd->priv;
581581
struct lpddr_private *lpddr = map->fldrv_priv;
582-
int chipnum = adr >> lpddr->chipshift;
582+
int chipnum = adr >> lpddr->chipshift, err = 0;
583583
unsigned long ofs;
584584

585585
/* 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)
603603
chip->ref_point_counter--;
604604
if (chip->ref_point_counter == 0)
605605
chip->state = FL_READY;
606-
} else
606+
} else {
607607
printk(KERN_WARNING "%s: Warning: unpoint called on non"
608608
"pointed region\n", map->name);
609+
err = -EINVAL;
610+
}
609611

610612
put_chip(map, chip);
611613
mutex_unlock(&chip->mutex);
@@ -614,6 +616,8 @@ static void lpddr_unpoint (struct mtd_info *mtd, loff_t adr, size_t len)
614616
ofs = 0;
615617
chipnum++;
616618
}
619+
620+
return err;
617621
}
618622

619623
static int lpddr_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,

drivers/mtd/mtdpart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
9292
virt, phys);
9393
}
9494

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)
9696
{
9797
struct mtd_part *part = PART(mtd);
9898

99-
mtd_unpoint(part->master, from + part->offset, len);
99+
return mtd_unpoint(part->master, from + part->offset, len);
100100
}
101101

102102
static unsigned long part_get_unmapped_area(struct mtd_info *mtd,

include/linux/mtd/mtd.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ struct mtd_info {
177177
int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
178178
int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
179179
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);
181181
unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
182182
unsigned long len,
183183
unsigned long offset,
@@ -265,8 +265,10 @@ static inline int mtd_point(struct mtd_info *mtd, loff_t from, size_t len,
265265
}
266266

267267
/* 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)
269269
{
270+
if (!mtd->_point)
271+
return -EOPNOTSUPP;
270272
return mtd->_unpoint(mtd, from, len);
271273
}
272274

include/linux/mtd/pmc551.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct mypriv {
3434
* Function Prototypes
3535
*/
3636
static int pmc551_erase(struct mtd_info *, struct erase_info *);
37-
static void pmc551_unpoint(struct mtd_info *, loff_t, size_t);
3837
static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
3938
size_t *retlen, void **virt, resource_size_t *phys);
4039
static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);

0 commit comments

Comments
 (0)