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

memory: renesas-rpc-if: fix platform-device leak in error path

Make sure to free the flash platform device in the event that
registration fails during probe.

Fixes: ca7d8b980b67 ("memory: add Renesas RPC-IF driver")
Cc: stable@vger.kernel.org # 5.8
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20220303180632.3194-1-johan@kernel.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

authored by

Johan Hovold and committed by
Krzysztof Kozlowski
b452dbf2 31231092

+9 -1
+9 -1
drivers/memory/renesas-rpc-if.c
··· 651 651 struct platform_device *vdev; 652 652 struct device_node *flash; 653 653 const char *name; 654 + int ret; 654 655 655 656 flash = of_get_next_child(pdev->dev.of_node, NULL); 656 657 if (!flash) { ··· 675 674 return -ENOMEM; 676 675 vdev->dev.parent = &pdev->dev; 677 676 platform_set_drvdata(pdev, vdev); 678 - return platform_device_add(vdev); 677 + 678 + ret = platform_device_add(vdev); 679 + if (ret) { 680 + platform_device_put(vdev); 681 + return ret; 682 + } 683 + 684 + return 0; 679 685 } 680 686 681 687 static int rpcif_remove(struct platform_device *pdev)