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

serial: vt8500: Cleanup code using devm_ function

Convert the last memory allocation (vt8500_port) to use devm_kzalloc
and remove the fail path cleanup code from vt8500_serial_probe.

Reorder iomem mapping above clk_enable to simplify fail code. The
clock is only enabled if all other resources are available.

Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tony Prisk and committed by
Greg Kroah-Hartman
49abd90c 12faa35a

+4 -9
+4 -9
drivers/tty/serial/vt8500_serial.c
··· 580 580 return -EBUSY; 581 581 } 582 582 583 - vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL); 583 + vt8500_port = devm_kzalloc(&pdev->dev, sizeof(struct vt8500_port), 584 + GFP_KERNEL); 584 585 if (!vt8500_port) 585 586 return -ENOMEM; 586 587 ··· 592 591 vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0); 593 592 if (IS_ERR(vt8500_port->clk)) { 594 593 dev_err(&pdev->dev, "failed to get clock\n"); 595 - ret = -EINVAL; 596 - goto err; 594 + return -EINVAL; 597 595 } 598 596 599 597 ret = clk_prepare_enable(vt8500_port->clk); 600 598 if (ret) { 601 599 dev_err(&pdev->dev, "failed to enable clock\n"); 602 - goto err; 600 + return ret; 603 601 } 604 602 605 603 vt8500_port->uart.type = PORT_VT8500; ··· 622 622 platform_set_drvdata(pdev, vt8500_port); 623 623 624 624 return 0; 625 - 626 - err: 627 - kfree(vt8500_port); 628 - return ret; 629 625 } 630 626 631 627 static int vt8500_serial_remove(struct platform_device *pdev) ··· 631 635 platform_set_drvdata(pdev, NULL); 632 636 clk_disable_unprepare(vt8500_port->clk); 633 637 uart_remove_one_port(&vt8500_uart_driver, &vt8500_port->uart); 634 - kfree(vt8500_port); 635 638 636 639 return 0; 637 640 }