]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soc: aspeed: lpc-snoop: Ensure model_data is valid
authorAndrew Jeffery <andrew@codeconstruct.com.au>
Mon, 16 Jun 2025 13:13:40 +0000 (22:43 +0930)
committerAndrew Jeffery <andrew@codeconstruct.com.au>
Tue, 8 Jul 2025 02:05:03 +0000 (11:35 +0930)
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 <jdelvare@suse.de>
Link: https://patch.msgid.link/20250616-aspeed-lpc-snoop-fixes-v2-3-3cdd59c934d3@codeconstruct.com.au
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
drivers/soc/aspeed/aspeed-lpc-snoop.c

index fc3a2c41cc10739f5f70ded7ac02baab6468d652..ca7536213e0986f737606a52996ffea620df2a7a 100644 (file)
@@ -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;