Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: max17042_battery: Always fall back to default platform-data

It is possible to have CONFIG_OF enabled on x86 builds, where we have no
firmware provided max17042_platform_data. The CONFIG_OF implementation of
max17042_get_pdata would return NULL in this case, causing the probe to
fail.

Instead always fallback to the default platform-data, as used on x86 sofar,
when there is no firmware provided pdata, independent of CONFIG_OF.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>

authored by

Hans de Goede and committed by
Sebastian Reichel
2d7e6a83 6e5ab19d

+18 -9
+18 -9
drivers/power/supply/max17042_battery.c
··· 886 886 887 887 #ifdef CONFIG_OF 888 888 static struct max17042_platform_data * 889 - max17042_get_pdata(struct max17042_chip *chip) 889 + max17042_get_of_pdata(struct max17042_chip *chip) 890 890 { 891 891 struct device *dev = &chip->client->dev; 892 892 struct device_node *np = dev->of_node; 893 893 u32 prop; 894 894 struct max17042_platform_data *pdata; 895 - 896 - if (!np) 897 - return dev->platform_data; 898 895 899 896 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 900 897 if (!pdata) ··· 917 920 918 921 return pdata; 919 922 } 920 - #else 923 + #endif 924 + 921 925 static struct max17042_reg_data max17047_default_pdata_init_regs[] = { 922 926 /* 923 927 * Some firmwares do not set FullSOCThr, Enable End-of-Charge Detection ··· 928 930 }; 929 931 930 932 static struct max17042_platform_data * 931 - max17042_get_pdata(struct max17042_chip *chip) 933 + max17042_get_default_pdata(struct max17042_chip *chip) 932 934 { 933 935 struct device *dev = &chip->client->dev; 934 936 struct max17042_platform_data *pdata; 935 937 int ret, misc_cfg; 936 - 937 - if (dev->platform_data) 938 - return dev->platform_data; 939 938 940 939 /* 941 940 * The MAX17047 gets used on x86 where we might not have pdata, assume ··· 966 971 967 972 return pdata; 968 973 } 974 + 975 + static struct max17042_platform_data * 976 + max17042_get_pdata(struct max17042_chip *chip) 977 + { 978 + struct device *dev = &chip->client->dev; 979 + 980 + #ifdef CONFIG_OF 981 + if (dev->of_node) 982 + return max17042_get_of_pdata(chip); 969 983 #endif 984 + if (dev->platform_data) 985 + return dev->platform_data; 986 + 987 + return max17042_get_default_pdata(chip); 988 + } 970 989 971 990 static const struct regmap_config max17042_regmap_config = { 972 991 .reg_bits = 8,