Re: [PATCH 3/7] soc: aspeed: lpc-snoop: Ensure model_data is valid

Jean Delvare
2025-04-16T12:19:44Z

On Fri, 11 Apr 2025 10:38:33 +0930, Andrew Jeffery wrote:
> of_device_get_match_data() can return NULL, though shouldn't in current
> circumstances. Regardless, initialise model_data closer to use so it's
> clear we need to test for validity prior to dereferencing.
>
> Fixes: 2dee584bc9e3 ("drivers/misc: (aspeed-lpc-snoop): Add ast2400 to compat")
> Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
> ---
> drivers/soc/aspeed/aspeed-lpc-snoop.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> index e9d9a8e60a6f062c0b53c9c02e5d73768453998d..28f034b8a3b7226efe20cbe30a7da0c2b49fbd96 100644
> --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
> +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> @@ -186,10 +186,10 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
> struct device *dev,
> int channel, u16 lpc_port)
> {
> - int rc = 0;
> + const struct aspeed_lpc_snoop_model_data *model_data;
> u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en;
> - const struct aspeed_lpc_snoop_model_data *model_data =
> - of_device_get_match_data(dev);
> + int rc = 0;
> +

Duplicate blank line.

>
> if (lpc_snoop->chan[channel].enabled)
> return -EBUSY;
> @@ -236,9 +236,10 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
> regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en);
> regmap_update_bits(lpc_snoop->regmap, SNPWADR, snpwadr_mask,
> lpc_port << snpwadr_shift);
> - if (model_data->has_hicrb_ensnp)
> - regmap_update_bits(lpc_snoop->regmap, HICRB,
> - hicrb_en, hicrb_en);
> +
> + model_data = of_device_get_match_data(dev);
> + if (model_data && model_data->has_hicrb_ensnp)
> + regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en);
>
> lpc_snoop->chan[channel].enabled = true;
>
>

Acked-by: Jean Delvare <jdelvare@suse.de>

--
Jean Delvare
SUSE L3 Support