pinctrl: sunplus: Add check for kmalloc
[ Upstream commit a5961bed5429cf1134d7f539b4ed60317012f84d ]
Fix Smatch static checker warning:
potential null dereference 'configs'. (kmalloc returns null)
Fixes: aa74c44be1
("pinctrl: Add driver for Sunplus SP7021")
Signed-off-by: Wells Lu <wellslutw@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/1685277277-12209-1-git-send-email-wellslutw@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
bc796f65cd
commit
019d4fd93a
@ -838,11 +838,6 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node
|
|||||||
int i, size = 0;
|
int i, size = 0;
|
||||||
|
|
||||||
list = of_get_property(np_config, "sunplus,pins", &size);
|
list = of_get_property(np_config, "sunplus,pins", &size);
|
||||||
|
|
||||||
if (nmG <= 0)
|
|
||||||
nmG = 0;
|
|
||||||
|
|
||||||
parent = of_get_parent(np_config);
|
|
||||||
*num_maps = size / sizeof(*list);
|
*num_maps = size / sizeof(*list);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -870,10 +865,14 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nmG <= 0)
|
||||||
|
nmG = 0;
|
||||||
|
|
||||||
*map = kcalloc(*num_maps + nmG, sizeof(**map), GFP_KERNEL);
|
*map = kcalloc(*num_maps + nmG, sizeof(**map), GFP_KERNEL);
|
||||||
if (*map == NULL)
|
if (!(*map))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
parent = of_get_parent(np_config);
|
||||||
for (i = 0; i < (*num_maps); i++) {
|
for (i = 0; i < (*num_maps); i++) {
|
||||||
dt_pin = be32_to_cpu(list[i]);
|
dt_pin = be32_to_cpu(list[i]);
|
||||||
pin_num = FIELD_GET(GENMASK(31, 24), dt_pin);
|
pin_num = FIELD_GET(GENMASK(31, 24), dt_pin);
|
||||||
@ -887,6 +886,8 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node
|
|||||||
(*map)[i].data.configs.num_configs = 1;
|
(*map)[i].data.configs.num_configs = 1;
|
||||||
(*map)[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_num);
|
(*map)[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_num);
|
||||||
configs = kmalloc(sizeof(*configs), GFP_KERNEL);
|
configs = kmalloc(sizeof(*configs), GFP_KERNEL);
|
||||||
|
if (!configs)
|
||||||
|
goto sppctl_map_err;
|
||||||
*configs = FIELD_GET(GENMASK(7, 0), dt_pin);
|
*configs = FIELD_GET(GENMASK(7, 0), dt_pin);
|
||||||
(*map)[i].data.configs.configs = configs;
|
(*map)[i].data.configs.configs = configs;
|
||||||
|
|
||||||
@ -900,6 +901,8 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node
|
|||||||
(*map)[i].data.configs.num_configs = 1;
|
(*map)[i].data.configs.num_configs = 1;
|
||||||
(*map)[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_num);
|
(*map)[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_num);
|
||||||
configs = kmalloc(sizeof(*configs), GFP_KERNEL);
|
configs = kmalloc(sizeof(*configs), GFP_KERNEL);
|
||||||
|
if (!configs)
|
||||||
|
goto sppctl_map_err;
|
||||||
*configs = SPPCTL_IOP_CONFIGS;
|
*configs = SPPCTL_IOP_CONFIGS;
|
||||||
(*map)[i].data.configs.configs = configs;
|
(*map)[i].data.configs.configs = configs;
|
||||||
|
|
||||||
@ -969,6 +972,15 @@ static int sppctl_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node
|
|||||||
of_node_put(parent);
|
of_node_put(parent);
|
||||||
dev_dbg(pctldev->dev, "%d pins mapped\n", *num_maps);
|
dev_dbg(pctldev->dev, "%d pins mapped\n", *num_maps);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
sppctl_map_err:
|
||||||
|
for (i = 0; i < (*num_maps); i++)
|
||||||
|
if (((*map)[i].type == PIN_MAP_TYPE_CONFIGS_PIN) &&
|
||||||
|
(*map)[i].data.configs.configs)
|
||||||
|
kfree((*map)[i].data.configs.configs);
|
||||||
|
kfree(*map);
|
||||||
|
of_node_put(parent);
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct pinctrl_ops sppctl_pctl_ops = {
|
static const struct pinctrl_ops sppctl_pctl_ops = {
|
||||||
|
Loading…
Reference in New Issue
Block a user