hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/mtd/chips/cfi_cmdset_0001.c
....@@ -420,8 +420,9 @@
420420 extra_size = 0;
421421
422422 /* Protection Register info */
423
- extra_size += (extp->NumProtectionFields - 1) *
424
- sizeof(struct cfi_intelext_otpinfo);
423
+ if (extp->NumProtectionFields)
424
+ extra_size += (extp->NumProtectionFields - 1) *
425
+ sizeof(struct cfi_intelext_otpinfo);
425426 }
426427
427428 if (extp->MinorVersion >= '1') {
....@@ -695,14 +696,16 @@
695696 */
696697 if (extp && extp->MajorVersion == '1' && extp->MinorVersion >= '3'
697698 && extp->FeatureSupport & (1 << 9)) {
699
+ int offs = 0;
698700 struct cfi_private *newcfi;
699701 struct flchip *chip;
700702 struct flchip_shared *shared;
701
- int offs, numregions, numparts, partshift, numvirtchips, i, j;
703
+ int numregions, numparts, partshift, numvirtchips, i, j;
702704
703705 /* Protection Register info */
704
- offs = (extp->NumProtectionFields - 1) *
705
- sizeof(struct cfi_intelext_otpinfo);
706
+ if (extp->NumProtectionFields)
707
+ offs = (extp->NumProtectionFields - 1) *
708
+ sizeof(struct cfi_intelext_otpinfo);
706709
707710 /* Burst Read info */
708711 offs += extp->extra[offs+1]+2;
....@@ -756,7 +759,8 @@
756759 }
757760
758761 numvirtchips = cfi->numchips * numparts;
759
- newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL);
762
+ newcfi = kmalloc(struct_size(newcfi, chips, numvirtchips),
763
+ GFP_KERNEL);
760764 if (!newcfi)
761765 return -ENOMEM;
762766 shared = kmalloc_array(cfi->numchips,
....@@ -833,7 +837,7 @@
833837 /* Someone else might have been playing with it. */
834838 return -EAGAIN;
835839 }
836
- /* Fall through */
840
+ fallthrough;
837841 case FL_READY:
838842 case FL_CFI_QUERY:
839843 case FL_JEDEC_QUERY:
....@@ -906,7 +910,7 @@
906910 /* Only if there's no operation suspended... */
907911 if (mode == FL_READY && chip->oldstate == FL_READY)
908912 return 0;
909
- /* Fall through */
913
+ fallthrough;
910914 default:
911915 sleep:
912916 set_current_state(TASK_UNINTERRUPTIBLE);
....@@ -1352,7 +1356,7 @@
13521356 {
13531357 unsigned long cmd_addr;
13541358 struct cfi_private *cfi = map->fldrv_priv;
1355
- int ret = 0;
1359
+ int ret;
13561360
13571361 adr += chip->start;
13581362
....@@ -1382,7 +1386,7 @@
13821386 struct cfi_private *cfi = map->fldrv_priv;
13831387 unsigned long ofs, last_end = 0;
13841388 int chipnum;
1385
- int ret = 0;
1389
+ int ret;
13861390
13871391 if (!map->virt)
13881392 return -EINVAL;
....@@ -1549,7 +1553,7 @@
15491553 {
15501554 struct cfi_private *cfi = map->fldrv_priv;
15511555 map_word status, write_cmd;
1552
- int ret=0;
1556
+ int ret;
15531557
15541558 adr += chip->start;
15551559
....@@ -1623,7 +1627,7 @@
16231627 {
16241628 struct map_info *map = mtd->priv;
16251629 struct cfi_private *cfi = map->fldrv_priv;
1626
- int ret = 0;
1630
+ int ret;
16271631 int chipnum;
16281632 unsigned long ofs;
16291633
....@@ -1870,7 +1874,7 @@
18701874 struct map_info *map = mtd->priv;
18711875 struct cfi_private *cfi = map->fldrv_priv;
18721876 int wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
1873
- int ret = 0;
1877
+ int ret;
18741878 int chipnum;
18751879 unsigned long ofs, vec_seek, i;
18761880 size_t len = 0;