[PATCH] net: designware: rockchip: future-proof driver for more SoCs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux