@@ -888,8 +888,8 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd,
888888
889889 /* OTP nvmem will be registered on the physical device */
890890 config .dev = mtd -> dev .parent ;
891- config .name = kasprintf ( GFP_KERNEL , "%s-%s" , dev_name ( & mtd -> dev ), compatible ) ;
892- config .id = NVMEM_DEVID_NONE ;
891+ config .name = compatible ;
892+ config .id = NVMEM_DEVID_AUTO ;
893893 config .owner = THIS_MODULE ;
894894 config .type = NVMEM_TYPE_OTP ;
895895 config .root_only = true;
@@ -905,7 +905,6 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd,
905905 nvmem = NULL ;
906906
907907 of_node_put (np );
908- kfree (config .name );
909908
910909 return nvmem ;
911910}
@@ -940,6 +939,7 @@ static int mtd_nvmem_fact_otp_reg_read(void *priv, unsigned int offset,
940939
941940static int mtd_otp_nvmem_add (struct mtd_info * mtd )
942941{
942+ struct device * dev = mtd -> dev .parent ;
943943 struct nvmem_device * nvmem ;
944944 ssize_t size ;
945945 int err ;
@@ -953,8 +953,8 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
953953 nvmem = mtd_otp_nvmem_register (mtd , "user-otp" , size ,
954954 mtd_nvmem_user_otp_reg_read );
955955 if (IS_ERR (nvmem )) {
956- dev_err ( & mtd -> dev , "Failed to register OTP NVMEM device\n" );
957- return PTR_ERR ( nvmem ) ;
956+ err = PTR_ERR ( nvmem );
957+ goto err ;
958958 }
959959 mtd -> otp_user_nvmem = nvmem ;
960960 }
@@ -971,7 +971,6 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
971971 nvmem = mtd_otp_nvmem_register (mtd , "factory-otp" , size ,
972972 mtd_nvmem_fact_otp_reg_read );
973973 if (IS_ERR (nvmem )) {
974- dev_err (& mtd -> dev , "Failed to register OTP NVMEM device\n" );
975974 err = PTR_ERR (nvmem );
976975 goto err ;
977976 }
@@ -983,7 +982,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
983982
984983err :
985984 nvmem_unregister (mtd -> otp_user_nvmem );
986- return err ;
985+ return dev_err_probe ( dev , err , "Failed to register OTP NVMEM device\n" ) ;
987986}
988987
989988/**
@@ -1023,10 +1022,14 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
10231022
10241023 mtd_set_dev_defaults (mtd );
10251024
1025+ ret = mtd_otp_nvmem_add (mtd );
1026+ if (ret )
1027+ goto out ;
1028+
10261029 if (IS_ENABLED (CONFIG_MTD_PARTITIONED_MASTER )) {
10271030 ret = add_mtd_device (mtd );
10281031 if (ret )
1029- return ret ;
1032+ goto out ;
10301033 }
10311034
10321035 /* Prefer parsed partitions over driver-provided fallback */
@@ -1061,9 +1064,12 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
10611064 register_reboot_notifier (& mtd -> reboot_notifier );
10621065 }
10631066
1064- ret = mtd_otp_nvmem_add (mtd );
1065-
10661067out :
1068+ if (ret ) {
1069+ nvmem_unregister (mtd -> otp_user_nvmem );
1070+ nvmem_unregister (mtd -> otp_factory_nvmem );
1071+ }
1072+
10671073 if (ret && device_is_registered (& mtd -> dev ))
10681074 del_mtd_device (mtd );
10691075
0 commit comments