[PATCH v2 08/11] staging: mt7621-gpio: avoid devm_kzalloc() hidden inside declarations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Driver probe function includes a 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.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@xxxxxxxxx>
---
 drivers/staging/mt7621-gpio/gpio-mt7621.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/mt7621-gpio/gpio-mt7621.c b/drivers/staging/mt7621-gpio/gpio-mt7621.c
index c701259..2d16d62 100644
--- a/drivers/staging/mt7621-gpio/gpio-mt7621.c
+++ b/drivers/staging/mt7621-gpio/gpio-mt7621.c
@@ -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);
 	const __be32 *id = of_get_property(bank, "reg", NULL);
-	struct mtk_gc *rg = devm_kzalloc(&pdev->dev,
-				sizeof(struct mtk_gc), GFP_KERNEL);
+	struct mtk_gc *rg;
 	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;
 
 	gpio_data->gc_map[be32_to_cpu(*id)] = rg;
 
-	memset(rg, 0, sizeof(struct mtk_gc));
-
 	spin_lock_init(&rg->lock);
 
 	rg->chip.parent = &pdev->dev;
-- 
2.7.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux