Commit 4b78fc42 authored by Christian Riesch's avatar Christian Riesch Committed by Brian Norris

mtd: Add a retlen parameter to _get_{fact,user}_prot_info

Signed-off-by: default avatarChristian Riesch <christian.riesch@omicron.at>
Cc: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent 41bf1a24
...@@ -68,10 +68,10 @@ static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, s ...@@ -68,10 +68,10 @@ static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, s
static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t); static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t);
static int cfi_intelext_get_fact_prot_info (struct mtd_info *, static int cfi_intelext_get_fact_prot_info(struct mtd_info *, size_t,
struct otp_info *, size_t); size_t *, struct otp_info *);
static int cfi_intelext_get_user_prot_info (struct mtd_info *, static int cfi_intelext_get_user_prot_info(struct mtd_info *, size_t,
struct otp_info *, size_t); size_t *, struct otp_info *);
#endif #endif
static int cfi_intelext_suspend (struct mtd_info *); static int cfi_intelext_suspend (struct mtd_info *);
static void cfi_intelext_resume (struct mtd_info *); static void cfi_intelext_resume (struct mtd_info *);
...@@ -2394,24 +2394,19 @@ static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd, ...@@ -2394,24 +2394,19 @@ static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,
NULL, do_otp_lock, 1); NULL, do_otp_lock, 1);
} }
static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, size_t len,
struct otp_info *buf, size_t len) size_t *retlen, struct otp_info *buf)
{
size_t retlen;
int ret;
ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 0); {
return ret ? : retlen; return cfi_intelext_otp_walk(mtd, 0, len, retlen, (u_char *)buf,
NULL, 0);
} }
static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd, static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd, size_t len,
struct otp_info *buf, size_t len) size_t *retlen, struct otp_info *buf)
{ {
size_t retlen; return cfi_intelext_otp_walk(mtd, 0, len, retlen, (u_char *)buf,
int ret; NULL, 1);
ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 1);
return ret ? : retlen;
} }
#endif #endif
......
...@@ -439,8 +439,8 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -439,8 +439,8 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
#ifdef CONFIG_MTD_DATAFLASH_OTP #ifdef CONFIG_MTD_DATAFLASH_OTP
static int dataflash_get_otp_info(struct mtd_info *mtd, static int dataflash_get_otp_info(struct mtd_info *mtd, size_t len,
struct otp_info *info, size_t len) size_t *retlen, struct otp_info *info)
{ {
/* Report both blocks as identical: bytes 0..64, locked. /* Report both blocks as identical: bytes 0..64, locked.
* Unless the user block changed from all-ones, we can't * Unless the user block changed from all-ones, we can't
...@@ -449,7 +449,8 @@ static int dataflash_get_otp_info(struct mtd_info *mtd, ...@@ -449,7 +449,8 @@ static int dataflash_get_otp_info(struct mtd_info *mtd,
info->start = 0; info->start = 0;
info->length = 64; info->length = 64;
info->locked = 1; info->locked = 1;
return sizeof(*info); *retlen = sizeof(*info);
return 0;
} }
static ssize_t otp_read(struct spi_device *spi, unsigned base, static ssize_t otp_read(struct spi_device *spi, unsigned base,
......
...@@ -889,25 +889,26 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) ...@@ -889,25 +889,26 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
case OTPGETREGIONINFO: case OTPGETREGIONINFO:
{ {
struct otp_info *buf = kmalloc(4096, GFP_KERNEL); struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
size_t retlen;
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
switch (mfi->mode) { switch (mfi->mode) {
case MTD_FILE_MODE_OTP_FACTORY: case MTD_FILE_MODE_OTP_FACTORY:
ret = mtd_get_fact_prot_info(mtd, buf, 4096); ret = mtd_get_fact_prot_info(mtd, 4096, &retlen, buf);
break; break;
case MTD_FILE_MODE_OTP_USER: case MTD_FILE_MODE_OTP_USER:
ret = mtd_get_user_prot_info(mtd, buf, 4096); ret = mtd_get_user_prot_info(mtd, 4096, &retlen, buf);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
if (ret >= 0) { if (!ret) {
if (cmd == OTPGETREGIONCOUNT) { if (cmd == OTPGETREGIONCOUNT) {
int nbr = ret / sizeof(struct otp_info); int nbr = retlen / sizeof(struct otp_info);
ret = copy_to_user(argp, &nbr, sizeof(int)); ret = copy_to_user(argp, &nbr, sizeof(int));
} else } else
ret = copy_to_user(argp, buf, ret); ret = copy_to_user(argp, buf, retlen);
if (ret) if (ret)
ret = -EFAULT; ret = -EFAULT;
} }
......
...@@ -883,14 +883,14 @@ EXPORT_SYMBOL_GPL(mtd_read_oob); ...@@ -883,14 +883,14 @@ EXPORT_SYMBOL_GPL(mtd_read_oob);
* devices. The user data is one time programmable but the factory data is read * devices. The user data is one time programmable but the factory data is read
* only. * only.
*/ */
int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
size_t len) struct otp_info *buf)
{ {
if (!mtd->_get_fact_prot_info) if (!mtd->_get_fact_prot_info)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!len) if (!len)
return 0; return 0;
return mtd->_get_fact_prot_info(mtd, buf, len); return mtd->_get_fact_prot_info(mtd, len, retlen, buf);
} }
EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info); EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info);
...@@ -906,14 +906,14 @@ int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -906,14 +906,14 @@ int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
} }
EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg); EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg);
int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
size_t len) struct otp_info *buf)
{ {
if (!mtd->_get_user_prot_info) if (!mtd->_get_user_prot_info)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!len) if (!len)
return 0; return 0;
return mtd->_get_user_prot_info(mtd, buf, len); return mtd->_get_user_prot_info(mtd, len, retlen, buf);
} }
EXPORT_SYMBOL_GPL(mtd_get_user_prot_info); EXPORT_SYMBOL_GPL(mtd_get_user_prot_info);
......
...@@ -150,11 +150,12 @@ static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from, ...@@ -150,11 +150,12 @@ static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
retlen, buf); retlen, buf);
} }
static int part_get_user_prot_info(struct mtd_info *mtd, static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
struct otp_info *buf, size_t len) size_t *retlen, struct otp_info *buf)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
return part->master->_get_user_prot_info(part->master, buf, len); return part->master->_get_user_prot_info(part->master, len, retlen,
buf);
} }
static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
...@@ -165,11 +166,12 @@ static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, ...@@ -165,11 +166,12 @@ static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
retlen, buf); retlen, buf);
} }
static int part_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
size_t len) size_t *retlen, struct otp_info *buf)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
return part->master->_get_fact_prot_info(part->master, buf, len); return part->master->_get_fact_prot_info(part->master, len, retlen,
buf);
} }
static int part_write(struct mtd_info *mtd, loff_t to, size_t len, static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
......
...@@ -3237,20 +3237,17 @@ static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -3237,20 +3237,17 @@ static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,
/** /**
* onenand_get_fact_prot_info - [MTD Interface] Read factory OTP info * onenand_get_fact_prot_info - [MTD Interface] Read factory OTP info
* @param mtd MTD device structure * @param mtd MTD device structure
* @param buf the databuffer to put/get data
* @param len number of bytes to read * @param len number of bytes to read
* @param retlen pointer to variable to store the number of read bytes
* @param buf the databuffer to put/get data
* *
* Read factory OTP info. * Read factory OTP info.
*/ */
static int onenand_get_fact_prot_info(struct mtd_info *mtd, static int onenand_get_fact_prot_info(struct mtd_info *mtd, size_t len,
struct otp_info *buf, size_t len) size_t *retlen, struct otp_info *buf)
{ {
size_t retlen; return onenand_otp_walk(mtd, 0, len, retlen, (u_char *) buf, NULL,
int ret; MTD_OTP_FACTORY);
ret = onenand_otp_walk(mtd, 0, len, &retlen, (u_char *) buf, NULL, MTD_OTP_FACTORY);
return ret ? : retlen;
} }
/** /**
...@@ -3272,20 +3269,17 @@ static int onenand_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, ...@@ -3272,20 +3269,17 @@ static int onenand_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
/** /**
* onenand_get_user_prot_info - [MTD Interface] Read user OTP info * onenand_get_user_prot_info - [MTD Interface] Read user OTP info
* @param mtd MTD device structure * @param mtd MTD device structure
* @param buf the databuffer to put/get data * @param retlen pointer to variable to store the number of read bytes
* @param len number of bytes to read * @param len number of bytes to read
* @param buf the databuffer to put/get data
* *
* Read user OTP info. * Read user OTP info.
*/ */
static int onenand_get_user_prot_info(struct mtd_info *mtd, static int onenand_get_user_prot_info(struct mtd_info *mtd, size_t len,
struct otp_info *buf, size_t len) size_t *retlen, struct otp_info *buf)
{ {
size_t retlen; return onenand_otp_walk(mtd, 0, len, retlen, (u_char *) buf, NULL,
int ret; MTD_OTP_USER);
ret = onenand_otp_walk(mtd, 0, len, &retlen, (u_char *) buf, NULL, MTD_OTP_USER);
return ret ? : retlen;
} }
/** /**
......
...@@ -204,12 +204,12 @@ struct mtd_info { ...@@ -204,12 +204,12 @@ struct mtd_info {
struct mtd_oob_ops *ops); struct mtd_oob_ops *ops);
int (*_write_oob) (struct mtd_info *mtd, loff_t to, int (*_write_oob) (struct mtd_info *mtd, loff_t to,
struct mtd_oob_ops *ops); struct mtd_oob_ops *ops);
int (*_get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
size_t len); size_t *retlen, struct otp_info *buf);
int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
size_t len, size_t *retlen, u_char *buf); size_t len, size_t *retlen, u_char *buf);
int (*_get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
size_t len); size_t *retlen, struct otp_info *buf);
int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from, int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
size_t len, size_t *retlen, u_char *buf); size_t len, size_t *retlen, u_char *buf);
int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to, int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
...@@ -278,12 +278,12 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to, ...@@ -278,12 +278,12 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
return mtd->_write_oob(mtd, to, ops); return mtd->_write_oob(mtd, to, ops);
} }
int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
size_t len); struct otp_info *buf);
int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf); size_t *retlen, u_char *buf);
int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
size_t len); struct otp_info *buf);
int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf); size_t *retlen, u_char *buf);
int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len, int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
......
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