Commit e9301a5a authored by Sergio Paracuellos's avatar Sergio Paracuellos Committed by Greg Kroah-Hartman

staging: mt7621-gpio: avoid devm_kzalloc() hidden inside declarations and refactor function a bit

Driver probe function includes an allocation using devm_kzalloc
which is "hidden" a bit inside the declarations. Extract this
to a better place to increase readability. Also because we are
allocating zeroed memory 'memset' statement is not needed at all.
Condition for checking for a valid gpio id is wrong and it should
be greater or equal instead of only greater so update to be the
good one.
Signed-off-by: default avatarSergio Paracuellos <sergio.paracuellos@gmail.com>
Reviewed-by: default avatarNeilBrown <neil@brown.name>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 10ca84f2
...@@ -156,17 +156,18 @@ mediatek_gpio_bank_probe(struct platform_device *pdev, struct device_node *bank) ...@@ -156,17 +156,18 @@ mediatek_gpio_bank_probe(struct platform_device *pdev, struct device_node *bank)
{ {
struct mtk_data *gpio_data = dev_get_drvdata(&pdev->dev); struct mtk_data *gpio_data = dev_get_drvdata(&pdev->dev);
const __be32 *id = of_get_property(bank, "reg", NULL); const __be32 *id = of_get_property(bank, "reg", NULL);
struct mtk_gc *rg = devm_kzalloc(&pdev->dev, struct mtk_gc *rg;
sizeof(struct mtk_gc), GFP_KERNEL);
int ret; int ret;
if (!rg || !id || be32_to_cpu(*id) > MTK_MAX_BANK) if (!id || be32_to_cpu(*id) >= MTK_MAX_BANK)
return -EINVAL;
rg = devm_kzalloc(&pdev->dev, sizeof(struct mtk_gc), GFP_KERNEL);
if (!rg)
return -ENOMEM; return -ENOMEM;
gpio_data->gc_map[be32_to_cpu(*id)] = rg; gpio_data->gc_map[be32_to_cpu(*id)] = rg;
memset(rg, 0, sizeof(struct mtk_gc));
spin_lock_init(&rg->lock); spin_lock_init(&rg->lock);
rg->chip.parent = &pdev->dev; rg->chip.parent = &pdev->dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment