From: Andrew Jeffery Date: Mon, 16 Jun 2025 13:13:40 +0000 (+0930) Subject: soc: aspeed: lpc-snoop: Ensure model_data is valid X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3795e993931f2120bf64b8cdf03bb8c4f988b920;p=thirdparty%2Flinux.git soc: aspeed: lpc-snoop: Ensure model_data is valid 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. Acked-by: Jean Delvare Link: https://patch.msgid.link/20250616-aspeed-lpc-snoop-fixes-v2-3-3cdd59c934d3@codeconstruct.com.au Signed-off-by: Andrew Jeffery --- diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index fc3a2c41cc107..ca7536213e098 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -186,10 +186,9 @@ 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; if (WARN_ON(lpc_snoop->chan[channel].enabled)) return -EBUSY; @@ -236,9 +235,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;