linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: core: Fix size overflow for mmc partitions
@ 2019-10-31  1:11 Bradley Bolen
  2019-11-04 13:37 ` Avri Altman
  0 siblings, 1 reply; 2+ messages in thread
From: Bradley Bolen @ 2019-10-31  1:11 UTC (permalink / raw)
  To: linux-mmc
  Cc: linux-kernel, ulf.hansson, kstewart, tglx, info, hongjiefang,
	avri.altman, wsa+renesas, yinbo.zhu, Bradley Bolen

With large eMMC cards, it is possible to create general purpose
partitions that are bigger than 4GB.  The size member of the mmc_part
struct is only an unsigned int which overflows for gp partitions larger
than 4GB.  Change this to a u64 to handle the overflow.

Signed-off-by: Bradley Bolen <bradleybolen@gmail.com>
---
 drivers/mmc/core/mmc.c   | 4 ++--
 include/linux/mmc/card.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index c8804895595f..4e89cf6524a1 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -297,7 +297,7 @@ static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd)
 	}
 }
 
-static void mmc_part_add(struct mmc_card *card, unsigned int size,
+static void mmc_part_add(struct mmc_card *card, u64 size,
 			 unsigned int part_cfg, char *name, int idx, bool ro,
 			 int area_type)
 {
@@ -345,7 +345,7 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
 				ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
 			part_size *= (size_t)(hc_erase_grp_sz *
 				hc_wp_grp_sz);
-			mmc_part_add(card, part_size << 19,
+			mmc_part_add(card, (u64)part_size << 19,
 				EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
 				"gp%d", idx, false,
 				MMC_BLK_DATA_AREA_GP);
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 9b6336ad3266..b59d35bb50ba 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -226,7 +226,7 @@ struct mmc_queue_req;
  * MMC Physical partitions
  */
 struct mmc_part {
-	unsigned int	size;	/* partition size (in bytes) */
+	u64		size;	/* partition size (in bytes) */
 	unsigned int	part_cfg;	/* partition type */
 	char	name[MAX_MMC_PART_NAME_LEN];
 	bool	force_ro;	/* to make boot parts RO by default */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH] mmc: core: Fix size overflow for mmc partitions
  2019-10-31  1:11 [PATCH] mmc: core: Fix size overflow for mmc partitions Bradley Bolen
@ 2019-11-04 13:37 ` Avri Altman
  0 siblings, 0 replies; 2+ messages in thread
From: Avri Altman @ 2019-11-04 13:37 UTC (permalink / raw)
  To: Bradley Bolen, linux-mmc
  Cc: linux-kernel, ulf.hansson, kstewart, tglx, info, hongjiefang,
	wsa+renesas, yinbo.zhu

> 
> 
> With large eMMC cards, it is possible to create general purpose partitions that
> are bigger than 4GB.  The size member of the mmc_part struct is only an
> unsigned int which overflows for gp partitions larger than 4GB.  Change this to a
> u64 to handle the overflow.
> 
> Signed-off-by: Bradley Bolen <bradleybolen@gmail.com>
> ---
>  drivers/mmc/core/mmc.c   | 4 ++--
>  include/linux/mmc/card.h | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index
> c8804895595f..4e89cf6524a1 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -297,7 +297,7 @@ static void mmc_manage_enhanced_area(struct
> mmc_card *card, u8 *ext_csd)
>         }
>  }
> 
> -static void mmc_part_add(struct mmc_card *card, unsigned int size,
> +static void mmc_part_add(struct mmc_card *card, u64 size,
>                          unsigned int part_cfg, char *name, int idx, bool ro,
>                          int area_type)
>  {
> @@ -345,7 +345,7 @@ static void mmc_manage_gp_partitions(struct
> mmc_card *card, u8 *ext_csd)
>                                 ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>                         part_size *= (size_t)(hc_erase_grp_sz *
Need to adjust part_size as well.

Thanks,
Avri
>                                 hc_wp_grp_sz);
> -                       mmc_part_add(card, part_size << 19,
> +                       mmc_part_add(card, (u64)part_size << 19,
>                                 EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
>                                 "gp%d", idx, false,
>                                 MMC_BLK_DATA_AREA_GP); diff --git
> a/include/linux/mmc/card.h b/include/linux/mmc/card.h index
> 9b6336ad3266..b59d35bb50ba 100644
> --- a/include/linux/mmc/card.h
> +++ b/include/linux/mmc/card.h
> @@ -226,7 +226,7 @@ struct mmc_queue_req;
>   * MMC Physical partitions
>   */
>  struct mmc_part {
> -       unsigned int    size;   /* partition size (in bytes) */
> +       u64             size;   /* partition size (in bytes) */
>         unsigned int    part_cfg;       /* partition type */
>         char    name[MAX_MMC_PART_NAME_LEN];
>         bool    force_ro;       /* to make boot parts RO by default */
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-04 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31  1:11 [PATCH] mmc: core: Fix size overflow for mmc partitions Bradley Bolen
2019-11-04 13:37 ` Avri Altman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).