mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] net: designware: rockchip: future-proof driver for more SoCs
Date: Wed, 15 Jun 2022 10:03:05 +0200	[thread overview]
Message-ID: <20220615080305.954879-1-a.fatoum@pengutronix.de> (raw)

Linux driver has a struct rk_gmac_ops::regs_valid member to mark
whether regs is populated or not. Population happens via a GCC
extension that allows static initialization of flexible array
members. Replace that with a pointer that is checked, so future
SoC support just initializes it to NULL by default and avoid
the OOB access.

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

diff --git a/drivers/net/designware_rockchip.c b/drivers/net/designware_rockchip.c
index dcf65c9ad4cc..a3859dce0c62 100644
--- a/drivers/net/designware_rockchip.c
+++ b/drivers/net/designware_rockchip.c
@@ -21,7 +21,7 @@ struct rk_gmac_ops {
 	void (*set_rmii_speed)(struct eqos *eqos, int speed);
 	void (*set_rgmii_speed)(struct eqos *eqos, int speed);
 	void (*integrated_phy_powerup)(struct eqos *eqos);
-	u32 regs[];
+	const u32 *regs;
 };
 
 struct eqos_rk_gmac {
@@ -175,7 +175,7 @@ static const struct rk_gmac_ops rk3568_ops = {
 	.set_to_rmii = rk3568_set_to_rmii,
 	.set_rmii_speed = rk3568_set_gmac_speed,
 	.set_rgmii_speed = rk3568_set_gmac_speed,
-	.regs = {
+	.regs = (u32 []) {
 		0xfe2a0000, /* gmac0 */
 		0xfe010000, /* gmac1 */
 		0x0, /* sentinel */
@@ -253,7 +253,7 @@ static int eqos_init_rk_gmac(struct device_d *dev, struct eqos *eqos)
 
 	priv->ops = device_get_match_data(dev);
 
-	if (dev->num_resources > 0) {
+	if (dev->num_resources > 0 && priv->ops->regs) {
 		while (priv->ops->regs[i]) {
 			if (priv->ops->regs[i] == dev->resource[0].start) {
 				priv->bus_id = i;
-- 
2.30.2




             reply	other threads:[~2022-06-15  8:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15  8:03 Ahmad Fatoum [this message]
2022-06-17  7:31 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220615080305.954879-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH] net: designware: rockchip: future-proof driver for more SoCs' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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