mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net: designware: rockchip: future-proof driver for more SoCs
@ 2022-06-15  8:03 Ahmad Fatoum
  2022-06-17  7:31 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-06-15  8:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




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

* Re: [PATCH] net: designware: rockchip: future-proof driver for more SoCs
  2022-06-15  8:03 [PATCH] net: designware: rockchip: future-proof driver for more SoCs Ahmad Fatoum
@ 2022-06-17  7:31 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-06-17  7:31 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

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



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

end of thread, other threads:[~2022-06-17  7:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  8:03 [PATCH] net: designware: rockchip: future-proof driver for more SoCs Ahmad Fatoum
2022-06-17  7:31 ` Sascha Hauer

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