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

Sascha Hauer sha at pengutronix.de
Fri Jun 17 00:31:29 PDT 2022


On Wed, Jun 15, 2022 at 10:03:05AM +0200, Ahmad Fatoum wrote:
> 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 at pengutronix.de>
> ---
>  drivers/net/designware_rockchip.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Applied, thanks

Sascha

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

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



More information about the barebox mailing list