@@ -5225,8 +5225,11 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
52255225
52265226 sanitize_string (p -> manufacturer , sizeof (p -> manufacturer ));
52275227 sanitize_string (p -> model , sizeof (p -> model ));
5228- strncpy (chip -> parameters .model , p -> model ,
5229- sizeof (chip -> parameters .model ) - 1 );
5228+ chip -> parameters .model = kstrdup (p -> model , GFP_KERNEL );
5229+ if (!chip -> parameters .model ) {
5230+ ret = - ENOMEM ;
5231+ goto free_onfi_param_page ;
5232+ }
52305233
52315234 mtd -> writesize = le32_to_cpu (p -> byte_per_page );
52325235
@@ -5356,8 +5359,11 @@ static int nand_flash_detect_jedec(struct nand_chip *chip)
53565359
53575360 sanitize_string (p -> manufacturer , sizeof (p -> manufacturer ));
53585361 sanitize_string (p -> model , sizeof (p -> model ));
5359- strncpy (chip -> parameters .model , p -> model ,
5360- sizeof (chip -> parameters .model ) - 1 );
5362+ chip -> parameters .model = kstrdup (p -> model , GFP_KERNEL );
5363+ if (!chip -> parameters .model ) {
5364+ ret = - ENOMEM ;
5365+ goto free_jedec_param_page ;
5366+ }
53615367
53625368 mtd -> writesize = le32_to_cpu (p -> byte_per_page );
53635369
@@ -5546,8 +5552,9 @@ static bool find_full_id_nand(struct nand_chip *chip,
55465552 chip -> onfi_timing_mode_default =
55475553 type -> onfi_timing_mode_default ;
55485554
5549- strncpy (chip -> parameters .model , type -> name ,
5550- sizeof (chip -> parameters .model ) - 1 );
5555+ chip -> parameters .model = kstrdup (type -> name , GFP_KERNEL );
5556+ if (!chip -> parameters .model )
5557+ return false;
55515558
55525559 return true;
55535560 }
@@ -5706,8 +5713,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
57065713 if (!type -> name )
57075714 return - ENODEV ;
57085715
5709- strncpy (chip -> parameters .model , type -> name ,
5710- sizeof (chip -> parameters .model ) - 1 );
5716+ chip -> parameters .model = kstrdup (type -> name , GFP_KERNEL );
5717+ if (!chip -> parameters .model )
5718+ return - ENOMEM ;
57115719
57125720 chip -> chipsize = (uint64_t )type -> chipsize << 20 ;
57135721
@@ -5737,7 +5745,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
57375745 mtd -> name );
57385746 pr_warn ("bus width %d instead of %d bits\n" , busw ? 16 : 8 ,
57395747 (chip -> options & NAND_BUSWIDTH_16 ) ? 16 : 8 );
5740- return - EINVAL ;
5748+ ret = - EINVAL ;
5749+
5750+ goto free_detect_allocation ;
57415751 }
57425752
57435753 nand_decode_bbm_options (chip );
@@ -5774,6 +5784,11 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
57745784 (int )(chip -> chipsize >> 20 ), nand_is_slc (chip ) ? "SLC" : "MLC" ,
57755785 mtd -> erasesize >> 10 , mtd -> writesize , mtd -> oobsize );
57765786 return 0 ;
5787+
5788+ free_detect_allocation :
5789+ kfree (chip -> parameters .model );
5790+
5791+ return ret ;
57775792}
57785793
57795794static const char * const nand_ecc_modes [] = {
@@ -6013,6 +6028,11 @@ static int nand_scan_ident(struct mtd_info *mtd, int maxchips,
60136028 return 0 ;
60146029}
60156030
6031+ static void nand_scan_ident_cleanup (struct nand_chip * chip )
6032+ {
6033+ kfree (chip -> parameters .model );
6034+ }
6035+
60166036static int nand_set_ecc_soft_ops (struct mtd_info * mtd )
60176037{
60186038 struct nand_chip * chip = mtd_to_nand (mtd );
@@ -6760,11 +6780,18 @@ int nand_scan_with_ids(struct mtd_info *mtd, int maxchips,
67606780
67616781 ret = nand_attach (chip );
67626782 if (ret )
6763- return ret ;
6783+ goto cleanup_ident ;
67646784
67656785 ret = nand_scan_tail (mtd );
67666786 if (ret )
6767- nand_detach (chip );
6787+ goto detach_chip ;
6788+
6789+ return 0 ;
6790+
6791+ detach_chip :
6792+ nand_detach (chip );
6793+ cleanup_ident :
6794+ nand_scan_ident_cleanup (chip );
67686795
67696796 return ret ;
67706797}
@@ -6796,6 +6823,9 @@ void nand_cleanup(struct nand_chip *chip)
67966823
67976824 /* Free controller specific allocations after chip identification */
67986825 nand_detach (chip );
6826+
6827+ /* Free identification phase allocations */
6828+ nand_scan_ident_cleanup (chip );
67996829}
68006830
68016831EXPORT_SYMBOL_GPL (nand_cleanup );
0 commit comments