mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP
@ 2021-03-24 12:22 Ahmad Fatoum
  2021-03-24 12:22 ` [PATCH 2/4] clk: imx: clk-pllv1: fix wrong PLL recalc on i.MX1/i.MX21 Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2021-03-24 12:22 UTC (permalink / raw)
  To: barebox; +Cc: bst, Ahmad Fatoum

FIELD_PREP expects mask datatype to be a constant unsigned long.
The mask constant already has the correct datatype, so pass it directly.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/phy/at803x.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index e0e147b1913e..93a8bb9df10e 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -141,13 +141,12 @@ static int at803x_parse_dt(struct phy_device *phydev)
 	const struct device_d *dev = &phydev->dev;
 	const struct device_node *node = dev->device_node;
 	struct at803x_priv *priv = phydev->priv;
-	unsigned int sel, mask;
+	unsigned int sel;
 	u32 freq, strength;
 	int ret;
 
 	ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
 	if (!ret) {
-		mask = AT803X_CLK_OUT_MASK;
 		switch (freq) {
 		case 25000000:
 			sel = AT803X_CLK_OUT_25MHZ_XTAL;
@@ -166,8 +165,8 @@ static int at803x_parse_dt(struct phy_device *phydev)
 			return -EINVAL;
 		}
 
-		priv->clk_25m_reg |= FIELD_PREP(mask, sel);
-		priv->clk_25m_mask |= mask;
+		priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
+		priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
 
 		/* Fixup for the AR8030/AR8035. This chip has another mask and
 		 * doesn't support the DSP reference. Eg. the lowest bit of the
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 2/4] clk: imx: clk-pllv1: fix wrong PLL recalc on i.MX1/i.MX21
  2021-03-24 12:22 [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Ahmad Fatoum
@ 2021-03-24 12:22 ` Ahmad Fatoum
  2021-03-24 12:22 ` [PATCH 3/4] kbuild: add -Wtype-limits to compile flags Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2021-03-24 12:22 UTC (permalink / raw)
  To: barebox; +Cc: bst, Ahmad Fatoum

Adding -Wtype-limits to the build correctly detects that the
first branch (mfn < 0) is never taken as mfn is unsigned.

Import the Linux v5.11 bits that correctly checks the sign of the
sign/magnitude integer. Unlike Linux, we don't need to check
whether it's an i.MX1 or i.MX21 here, because an #ifdef earlier
normalizes the value to be aligned with the i.MX27's.

This however means that a multi-image barebox wasn't and will remain
not able to properly target both <= i.MX21 and newer SoCs at the same time.

This is just build-time tested.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/clk/imx/clk-pllv1.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/imx/clk-pllv1.c b/drivers/clk/imx/clk-pllv1.c
index 283ae843a75d..36192bb2112a 100644
--- a/drivers/clk/imx/clk-pllv1.c
+++ b/drivers/clk/imx/clk-pllv1.c
@@ -12,12 +12,21 @@
 
 #include "clk.h"
 
+#define MFN_BITS	(10)
+#define MFN_SIGN	(BIT(MFN_BITS - 1))
+#define MFN_MASK	(MFN_SIGN - 1)
+
 struct clk_pllv1 {
 	struct clk clk;
 	void __iomem *reg;
 	const char *parent;
 };
 
+static inline bool mfn_is_negative(unsigned int mfn)
+{
+    return mfn & MFN_SIGN;
+}
+
 static unsigned long clk_pllv1_recalc_rate(struct clk *clk,
 		unsigned long parent_rate)
 {
@@ -50,7 +59,7 @@ static unsigned long clk_pllv1_recalc_rate(struct clk *clk,
 	ll = (unsigned long long)freq * mfn_abs;
 
 	do_div(ll, mfd + 1);
-	if (mfn < 0)
+	if (mfn_is_negative(mfn))
 		ll = (freq * mfi) - ll;
 	else
 		ll = (freq * mfi) + ll;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 3/4] kbuild: add -Wtype-limits to compile flags
  2021-03-24 12:22 [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Ahmad Fatoum
  2021-03-24 12:22 ` [PATCH 2/4] clk: imx: clk-pllv1: fix wrong PLL recalc on i.MX1/i.MX21 Ahmad Fatoum
@ 2021-03-24 12:22 ` Ahmad Fatoum
  2021-03-24 12:22 ` [PATCH 4/4] mtd: fix possible overflow during mtd size multiplication Ahmad Fatoum
  2021-03-25 12:46 ` [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2021-03-24 12:22 UTC (permalink / raw)
  To: barebox; +Cc: bst, Ahmad Fatoum

Not warning about e.g. comparisons of unsigned integers with 0 can
introduce nasty bugs around error handling especially.

Enable the warning to be able to identify these issues in future.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Makefile b/Makefile
index 6d78d1f58eca..81ceedafeb0c 100644
--- a/Makefile
+++ b/Makefile
@@ -650,6 +650,9 @@ CHECKFLAGS     += $(NOSTDINC_FLAGS)
 # warn about C99 declaration after statement
 KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
 
+# warn about e.g. (unsigned)x < 0
+KBUILD_CFLAGS += $(call cc-option,-Wtype-limits)
+
 # disable pointer signed / unsigned warnings in gcc 4.0
 KBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
 
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* [PATCH 4/4] mtd: fix possible overflow during mtd size multiplication
  2021-03-24 12:22 [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Ahmad Fatoum
  2021-03-24 12:22 ` [PATCH 2/4] clk: imx: clk-pllv1: fix wrong PLL recalc on i.MX1/i.MX21 Ahmad Fatoum
  2021-03-24 12:22 ` [PATCH 3/4] kbuild: add -Wtype-limits to compile flags Ahmad Fatoum
@ 2021-03-24 12:22 ` Ahmad Fatoum
  2021-03-25 12:46 ` [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2021-03-24 12:22 UTC (permalink / raw)
  To: barebox; +Cc: bst, Ahmad Fatoum

LGTM[1] flags a couple of places where we write a 32-bit multiplication
result into a 64-bit destination. While it might very well be that
there are more places in need of fixing to support flashes bigger than
4G, fixing these issues is easy and reduces the noise. Do so.

[1]: https://lgtm.com/projects/g/saschahauer/barebox/alerts/?mode=list

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mtd/core.c            | 2 +-
 drivers/mtd/mtdoob.c          | 2 +-
 drivers/mtd/peb.c             | 4 ++--
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 22eb2a056c4e..37fccda6be27 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -131,7 +131,7 @@ static struct mtd_erase_region_info *mtd_find_erase_region(struct mtd_info *mtd,
 
 	for (i = 0; i < mtd->numeraseregions; i++) {
 		struct mtd_erase_region_info *e = &mtd->eraseregions[i];
-		if (offset > e->offset + e->erasesize * e->numblocks)
+		if (offset > e->offset + (loff_t)e->erasesize * e->numblocks)
 			continue;
 		return e;
 	}
diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c
index 04e064b227cb..19719c4d6279 100644
--- a/drivers/mtd/mtdoob.c
+++ b/drivers/mtd/mtdoob.c
@@ -77,7 +77,7 @@ static int add_mtdoob_device(struct mtd_info *mtd, const char *devname, void **p
 
 	mtdoob = xzalloc(sizeof(*mtdoob));
 	mtdoob->cdev.ops = &mtd_ops_oob;
-	mtdoob->cdev.size = mtd_div_by_wb(mtd->size, mtd) * mtd->oobsize;
+	mtdoob->cdev.size = mtd_div_by_wb(mtd->size, mtd) * (loff_t)mtd->oobsize;
 	mtdoob->cdev.name = basprintf("%s.oob", mtd->cdev.name);
 	mtdoob->cdev.priv = mtdoob;
 	mtdoob->cdev.dev = &mtd->dev;
diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index f3c51a61b4eb..03d96c2a5a7e 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -695,7 +695,7 @@ int mtd_peb_create_bitflips(struct mtd_info *mtd, int pnum, int offset,
 	ops.ooblen = mtd->oobsize;
 
 	for (i = 0; i < pages_per_block; i++) {
-		loff_t offs = (loff_t)pnum * mtd->erasesize + i * mtd->writesize;
+		loff_t offs = (loff_t)pnum * mtd->erasesize + i * (loff_t)mtd->writesize;
 
 		ops.datbuf = buf + i * mtd->writesize;
 		ops.oobbuf = oobbuf + i * mtd->oobsize;
@@ -738,7 +738,7 @@ int mtd_peb_create_bitflips(struct mtd_info *mtd, int pnum, int offset,
 	}
 
 	for (i = 0; i < pages_per_block; i++) {
-		loff_t offs = (loff_t)pnum * mtd->erasesize + i * mtd->writesize;
+		loff_t offs = (loff_t)pnum * mtd->erasesize + i * (loff_t)mtd->writesize;
 
 		ops.datbuf = buf + i * mtd->writesize;
 		ops.oobbuf = oobbuf + i * mtd->oobsize;
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index bd748ff5b4b3..383916e3f4b0 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1131,7 +1131,7 @@ static int spi_nor_init_params(struct spi_nor *nor,
 	memset(params, 0, sizeof(*params));
 
 	/* Set SPI NOR sizes. */
-	params->size = info->sector_size * info->n_sectors;
+	params->size = info->sector_size * (u64)info->n_sectors;
 	params->page_size = info->page_size;
 
 	/* (Fast) Read settings. */
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP
  2021-03-24 12:22 [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2021-03-24 12:22 ` [PATCH 4/4] mtd: fix possible overflow during mtd size multiplication Ahmad Fatoum
@ 2021-03-25 12:46 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2021-03-25 12:46 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, bst

On Wed, Mar 24, 2021 at 01:22:44PM +0100, Ahmad Fatoum wrote:
> FIELD_PREP expects mask datatype to be a constant unsigned long.
> The mask constant already has the correct datatype, so pass it directly.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/net/phy/at803x.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> index e0e147b1913e..93a8bb9df10e 100644
> --- a/drivers/net/phy/at803x.c
> +++ b/drivers/net/phy/at803x.c
> @@ -141,13 +141,12 @@ static int at803x_parse_dt(struct phy_device *phydev)
>  	const struct device_d *dev = &phydev->dev;
>  	const struct device_node *node = dev->device_node;
>  	struct at803x_priv *priv = phydev->priv;
> -	unsigned int sel, mask;
> +	unsigned int sel;
>  	u32 freq, strength;
>  	int ret;
>  
>  	ret = of_property_read_u32(node, "qca,clk-out-frequency", &freq);
>  	if (!ret) {
> -		mask = AT803X_CLK_OUT_MASK;
>  		switch (freq) {
>  		case 25000000:
>  			sel = AT803X_CLK_OUT_25MHZ_XTAL;
> @@ -166,8 +165,8 @@ static int at803x_parse_dt(struct phy_device *phydev)
>  			return -EINVAL;
>  		}
>  
> -		priv->clk_25m_reg |= FIELD_PREP(mask, sel);
> -		priv->clk_25m_mask |= mask;
> +		priv->clk_25m_reg |= FIELD_PREP(AT803X_CLK_OUT_MASK, sel);
> +		priv->clk_25m_mask |= AT803X_CLK_OUT_MASK;
>  
>  		/* Fixup for the AR8030/AR8035. This chip has another mask and
>  		 * doesn't support the DSP reference. Eg. the lowest bit of the
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2021-03-25 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 12:22 [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Ahmad Fatoum
2021-03-24 12:22 ` [PATCH 2/4] clk: imx: clk-pllv1: fix wrong PLL recalc on i.MX1/i.MX21 Ahmad Fatoum
2021-03-24 12:22 ` [PATCH 3/4] kbuild: add -Wtype-limits to compile flags Ahmad Fatoum
2021-03-24 12:22 ` [PATCH 4/4] mtd: fix possible overflow during mtd size multiplication Ahmad Fatoum
2021-03-25 12:46 ` [PATCH 1/4] net: phy: at803x: fix incorrect use of FIELD_PREP Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox