Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: Christian Riesch <christian.riesch@omicron.at>
Cc: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Christian Riesch and committed by
Brian Norris
4b78fc42 41bf1a24

+57 -64
+13 -18
drivers/mtd/chips/cfi_cmdset_0001.c
··· 68 68 static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 69 69 static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 70 70 static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t); 71 - static int cfi_intelext_get_fact_prot_info (struct mtd_info *, 72 - struct otp_info *, size_t); 73 - static int cfi_intelext_get_user_prot_info (struct mtd_info *, 74 - struct otp_info *, size_t); 71 + static int cfi_intelext_get_fact_prot_info(struct mtd_info *, size_t, 72 + size_t *, struct otp_info *); 73 + static int cfi_intelext_get_user_prot_info(struct mtd_info *, size_t, 74 + size_t *, struct otp_info *); 75 75 #endif 76 76 static int cfi_intelext_suspend (struct mtd_info *); 77 77 static void cfi_intelext_resume (struct mtd_info *); ··· 2394 2394 NULL, do_otp_lock, 1); 2395 2395 } 2396 2396 2397 - static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, 2398 - struct otp_info *buf, size_t len) 2399 - { 2400 - size_t retlen; 2401 - int ret; 2397 + static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, size_t len, 2398 + size_t *retlen, struct otp_info *buf) 2402 2399 2403 - ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 0); 2404 - return ret ? : retlen; 2400 + { 2401 + return cfi_intelext_otp_walk(mtd, 0, len, retlen, (u_char *)buf, 2402 + NULL, 0); 2405 2403 } 2406 2404 2407 - static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd, 2408 - struct otp_info *buf, size_t len) 2405 + static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd, size_t len, 2406 + size_t *retlen, struct otp_info *buf) 2409 2407 { 2410 - size_t retlen; 2411 - int ret; 2412 - 2413 - ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 1); 2414 - return ret ? : retlen; 2408 + return cfi_intelext_otp_walk(mtd, 0, len, retlen, (u_char *)buf, 2409 + NULL, 1); 2415 2410 } 2416 2411 2417 2412 #endif
+4 -3
drivers/mtd/devices/mtd_dataflash.c
··· 439 439 440 440 #ifdef CONFIG_MTD_DATAFLASH_OTP 441 441 442 - static int dataflash_get_otp_info(struct mtd_info *mtd, 443 - struct otp_info *info, size_t len) 442 + static int dataflash_get_otp_info(struct mtd_info *mtd, size_t len, 443 + size_t *retlen, struct otp_info *info) 444 444 { 445 445 /* Report both blocks as identical: bytes 0..64, locked. 446 446 * Unless the user block changed from all-ones, we can't ··· 449 449 info->start = 0; 450 450 info->length = 64; 451 451 info->locked = 1; 452 - return sizeof(*info); 452 + *retlen = sizeof(*info); 453 + return 0; 453 454 } 454 455 455 456 static ssize_t otp_read(struct spi_device *spi, unsigned base,
+6 -5
drivers/mtd/mtdchar.c
··· 889 889 case OTPGETREGIONINFO: 890 890 { 891 891 struct otp_info *buf = kmalloc(4096, GFP_KERNEL); 892 + size_t retlen; 892 893 if (!buf) 893 894 return -ENOMEM; 894 895 switch (mfi->mode) { 895 896 case MTD_FILE_MODE_OTP_FACTORY: 896 - ret = mtd_get_fact_prot_info(mtd, buf, 4096); 897 + ret = mtd_get_fact_prot_info(mtd, 4096, &retlen, buf); 897 898 break; 898 899 case MTD_FILE_MODE_OTP_USER: 899 - ret = mtd_get_user_prot_info(mtd, buf, 4096); 900 + ret = mtd_get_user_prot_info(mtd, 4096, &retlen, buf); 900 901 break; 901 902 default: 902 903 ret = -EINVAL; 903 904 break; 904 905 } 905 - if (ret >= 0) { 906 + if (!ret) { 906 907 if (cmd == OTPGETREGIONCOUNT) { 907 - int nbr = ret / sizeof(struct otp_info); 908 + int nbr = retlen / sizeof(struct otp_info); 908 909 ret = copy_to_user(argp, &nbr, sizeof(int)); 909 910 } else 910 - ret = copy_to_user(argp, buf, ret); 911 + ret = copy_to_user(argp, buf, retlen); 911 912 if (ret) 912 913 ret = -EFAULT; 913 914 }
+6 -6
drivers/mtd/mtdcore.c
··· 883 883 * devices. The user data is one time programmable but the factory data is read 884 884 * only. 885 885 */ 886 - int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, 887 - size_t len) 886 + int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, 887 + struct otp_info *buf) 888 888 { 889 889 if (!mtd->_get_fact_prot_info) 890 890 return -EOPNOTSUPP; 891 891 if (!len) 892 892 return 0; 893 - return mtd->_get_fact_prot_info(mtd, buf, len); 893 + return mtd->_get_fact_prot_info(mtd, len, retlen, buf); 894 894 } 895 895 EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info); 896 896 ··· 906 906 } 907 907 EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg); 908 908 909 - int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, 910 - size_t len) 909 + int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, 910 + struct otp_info *buf) 911 911 { 912 912 if (!mtd->_get_user_prot_info) 913 913 return -EOPNOTSUPP; 914 914 if (!len) 915 915 return 0; 916 - return mtd->_get_user_prot_info(mtd, buf, len); 916 + return mtd->_get_user_prot_info(mtd, len, retlen, buf); 917 917 } 918 918 EXPORT_SYMBOL_GPL(mtd_get_user_prot_info); 919 919
+8 -6
drivers/mtd/mtdpart.c
··· 150 150 retlen, buf); 151 151 } 152 152 153 - static int part_get_user_prot_info(struct mtd_info *mtd, 154 - struct otp_info *buf, size_t len) 153 + static int part_get_user_prot_info(struct mtd_info *mtd, size_t len, 154 + size_t *retlen, struct otp_info *buf) 155 155 { 156 156 struct mtd_part *part = PART(mtd); 157 - return part->master->_get_user_prot_info(part->master, buf, len); 157 + return part->master->_get_user_prot_info(part->master, len, retlen, 158 + buf); 158 159 } 159 160 160 161 static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, ··· 166 165 retlen, buf); 167 166 } 168 167 169 - static int part_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, 170 - size_t len) 168 + static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len, 169 + size_t *retlen, struct otp_info *buf) 171 170 { 172 171 struct mtd_part *part = PART(mtd); 173 - return part->master->_get_fact_prot_info(part->master, buf, len); 172 + return part->master->_get_fact_prot_info(part->master, len, retlen, 173 + buf); 174 174 } 175 175 176 176 static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
+12 -18
drivers/mtd/onenand/onenand_base.c
··· 3237 3237 /** 3238 3238 * onenand_get_fact_prot_info - [MTD Interface] Read factory OTP info 3239 3239 * @param mtd MTD device structure 3240 - * @param buf the databuffer to put/get data 3241 3240 * @param len number of bytes to read 3241 + * @param retlen pointer to variable to store the number of read bytes 3242 + * @param buf the databuffer to put/get data 3242 3243 * 3243 3244 * Read factory OTP info. 3244 3245 */ 3245 - static int onenand_get_fact_prot_info(struct mtd_info *mtd, 3246 - struct otp_info *buf, size_t len) 3246 + static int onenand_get_fact_prot_info(struct mtd_info *mtd, size_t len, 3247 + size_t *retlen, struct otp_info *buf) 3247 3248 { 3248 - size_t retlen; 3249 - int ret; 3250 - 3251 - ret = onenand_otp_walk(mtd, 0, len, &retlen, (u_char *) buf, NULL, MTD_OTP_FACTORY); 3252 - 3253 - return ret ? : retlen; 3249 + return onenand_otp_walk(mtd, 0, len, retlen, (u_char *) buf, NULL, 3250 + MTD_OTP_FACTORY); 3254 3251 } 3255 3252 3256 3253 /** ··· 3269 3272 /** 3270 3273 * onenand_get_user_prot_info - [MTD Interface] Read user OTP info 3271 3274 * @param mtd MTD device structure 3272 - * @param buf the databuffer to put/get data 3275 + * @param retlen pointer to variable to store the number of read bytes 3273 3276 * @param len number of bytes to read 3277 + * @param buf the databuffer to put/get data 3274 3278 * 3275 3279 * Read user OTP info. 3276 3280 */ 3277 - static int onenand_get_user_prot_info(struct mtd_info *mtd, 3278 - struct otp_info *buf, size_t len) 3281 + static int onenand_get_user_prot_info(struct mtd_info *mtd, size_t len, 3282 + size_t *retlen, struct otp_info *buf) 3279 3283 { 3280 - size_t retlen; 3281 - int ret; 3282 - 3283 - ret = onenand_otp_walk(mtd, 0, len, &retlen, (u_char *) buf, NULL, MTD_OTP_USER); 3284 - 3285 - return ret ? : retlen; 3284 + return onenand_otp_walk(mtd, 0, len, retlen, (u_char *) buf, NULL, 3285 + MTD_OTP_USER); 3286 3286 } 3287 3287 3288 3288 /**
+8 -8
include/linux/mtd/mtd.h
··· 204 204 struct mtd_oob_ops *ops); 205 205 int (*_write_oob) (struct mtd_info *mtd, loff_t to, 206 206 struct mtd_oob_ops *ops); 207 - int (*_get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, 208 - size_t len); 207 + int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len, 208 + size_t *retlen, struct otp_info *buf); 209 209 int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, 210 210 size_t len, size_t *retlen, u_char *buf); 211 - int (*_get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, 212 - size_t len); 211 + int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len, 212 + size_t *retlen, struct otp_info *buf); 213 213 int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from, 214 214 size_t len, size_t *retlen, u_char *buf); 215 215 int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to, ··· 278 278 return mtd->_write_oob(mtd, to, ops); 279 279 } 280 280 281 - int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, 282 - size_t len); 281 + int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, 282 + struct otp_info *buf); 283 283 int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, 284 284 size_t *retlen, u_char *buf); 285 - int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, 286 - size_t len); 285 + int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, 286 + struct otp_info *buf); 287 287 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, 288 288 size_t *retlen, u_char *buf); 289 289 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,