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

platform/mellanox: mlxreg-lc: Fix error flow and extend verbosity

Fix error flow:
- Clean-up client object in case of probing failure.
- Prevent running remove routine in case of probing failure.
Probing and removing are invoked by hotplug events raised upon line
card insertion and removing. If probing procedure failed all data is
cleared and there is nothing to do in remove routine.

Fixes: 62f9529b8d5c ("platform/mellanox: mlxreg-lc: Add initial support for Nvidia line card devices")
Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
Link: https://lore.kernel.org/r/20220719153540.61304-1-vadimp@nvidia.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Vadim Pasternak and committed by
Hans de Goede
b4b830a3 c9d959fc

+63 -19
+63 -19
drivers/platform/mellanox/mlxreg-lc.c
··· 716 716 switch (regval) { 717 717 case MLXREG_LC_SN4800_C16: 718 718 err = mlxreg_lc_sn4800_c16_config_init(mlxreg_lc, regmap, data); 719 - if (err) 719 + if (err) { 720 + dev_err(dev, "Failed to config client %s at bus %d at addr 0x%02x\n", 721 + data->hpdev.brdinfo->type, data->hpdev.nr, 722 + data->hpdev.brdinfo->addr); 720 723 return err; 724 + } 721 725 break; 722 726 default: 723 727 return -ENODEV; ··· 734 730 mlxreg_lc->mux = platform_device_register_resndata(dev, "i2c-mux-mlxcpld", data->hpdev.nr, 735 731 NULL, 0, mlxreg_lc->mux_data, 736 732 sizeof(*mlxreg_lc->mux_data)); 737 - if (IS_ERR(mlxreg_lc->mux)) 733 + if (IS_ERR(mlxreg_lc->mux)) { 734 + dev_err(dev, "Failed to create mux infra for client %s at bus %d at addr 0x%02x\n", 735 + data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); 738 736 return PTR_ERR(mlxreg_lc->mux); 737 + } 739 738 740 739 /* Register IO access driver. */ 741 740 if (mlxreg_lc->io_data) { ··· 747 740 platform_device_register_resndata(dev, "mlxreg-io", data->hpdev.nr, NULL, 0, 748 741 mlxreg_lc->io_data, sizeof(*mlxreg_lc->io_data)); 749 742 if (IS_ERR(mlxreg_lc->io_regs)) { 743 + dev_err(dev, "Failed to create regio for client %s at bus %d at addr 0x%02x\n", 744 + data->hpdev.brdinfo->type, data->hpdev.nr, 745 + data->hpdev.brdinfo->addr); 750 746 err = PTR_ERR(mlxreg_lc->io_regs); 751 747 goto fail_register_io; 752 748 } ··· 763 753 mlxreg_lc->led_data, 764 754 sizeof(*mlxreg_lc->led_data)); 765 755 if (IS_ERR(mlxreg_lc->led)) { 756 + dev_err(dev, "Failed to create LED objects for client %s at bus %d at addr 0x%02x\n", 757 + data->hpdev.brdinfo->type, data->hpdev.nr, 758 + data->hpdev.brdinfo->addr); 766 759 err = PTR_ERR(mlxreg_lc->led); 767 760 goto fail_register_led; 768 761 } ··· 822 809 if (!data->hpdev.adapter) { 823 810 dev_err(&pdev->dev, "Failed to get adapter for bus %d\n", 824 811 data->hpdev.nr); 825 - return -EFAULT; 812 + err = -EFAULT; 813 + goto i2c_get_adapter_fail; 826 814 } 827 815 828 816 /* Create device at the top of line card I2C tree.*/ ··· 832 818 if (IS_ERR(data->hpdev.client)) { 833 819 dev_err(&pdev->dev, "Failed to create client %s at bus %d at addr 0x%02x\n", 834 820 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); 835 - 836 - i2c_put_adapter(data->hpdev.adapter); 837 - data->hpdev.adapter = NULL; 838 - return PTR_ERR(data->hpdev.client); 821 + err = PTR_ERR(data->hpdev.client); 822 + goto i2c_new_device_fail; 839 823 } 840 824 841 825 regmap = devm_regmap_init_i2c(data->hpdev.client, 842 826 &mlxreg_lc_regmap_conf); 843 827 if (IS_ERR(regmap)) { 828 + dev_err(&pdev->dev, "Failed to create regmap for client %s at bus %d at addr 0x%02x\n", 829 + data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); 844 830 err = PTR_ERR(regmap); 845 - goto mlxreg_lc_probe_fail; 831 + goto devm_regmap_init_i2c_fail; 846 832 } 847 833 848 834 /* Set default registers. */ 849 835 for (i = 0; i < mlxreg_lc_regmap_conf.num_reg_defaults; i++) { 850 836 err = regmap_write(regmap, mlxreg_lc_regmap_default[i].reg, 851 837 mlxreg_lc_regmap_default[i].def); 852 - if (err) 853 - goto mlxreg_lc_probe_fail; 838 + if (err) { 839 + dev_err(&pdev->dev, "Failed to set default regmap %d for client %s at bus %d at addr 0x%02x\n", 840 + i, data->hpdev.brdinfo->type, data->hpdev.nr, 841 + data->hpdev.brdinfo->addr); 842 + goto regmap_write_fail; 843 + } 854 844 } 855 845 856 846 /* Sync registers with hardware. */ 857 847 regcache_mark_dirty(regmap); 858 848 err = regcache_sync(regmap); 859 - if (err) 860 - goto mlxreg_lc_probe_fail; 849 + if (err) { 850 + dev_err(&pdev->dev, "Failed to sync regmap for client %s at bus %d at addr 0x%02x\n", 851 + data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); 852 + err = PTR_ERR(regmap); 853 + goto regcache_sync_fail; 854 + } 861 855 862 856 par_pdata = data->hpdev.brdinfo->platform_data; 863 857 mlxreg_lc->par_regmap = par_pdata->regmap; ··· 876 854 /* Configure line card. */ 877 855 err = mlxreg_lc_config_init(mlxreg_lc, regmap, data); 878 856 if (err) 879 - goto mlxreg_lc_probe_fail; 857 + goto mlxreg_lc_config_init_fail; 880 858 881 859 return err; 882 860 883 - mlxreg_lc_probe_fail: 861 + mlxreg_lc_config_init_fail: 862 + regcache_sync_fail: 863 + regmap_write_fail: 864 + devm_regmap_init_i2c_fail: 865 + if (data->hpdev.client) { 866 + i2c_unregister_device(data->hpdev.client); 867 + data->hpdev.client = NULL; 868 + } 869 + i2c_new_device_fail: 884 870 i2c_put_adapter(data->hpdev.adapter); 871 + data->hpdev.adapter = NULL; 872 + i2c_get_adapter_fail: 873 + /* Clear event notification callback and handle. */ 874 + if (data->notifier) { 875 + data->notifier->user_handler = NULL; 876 + data->notifier->handle = NULL; 877 + } 885 878 return err; 886 879 } 887 880 ··· 905 868 struct mlxreg_core_data *data = dev_get_platdata(&pdev->dev); 906 869 struct mlxreg_lc *mlxreg_lc = platform_get_drvdata(pdev); 907 870 908 - /* Clear event notification callback. */ 909 - if (data->notifier) { 910 - data->notifier->user_handler = NULL; 911 - data->notifier->handle = NULL; 912 - } 871 + /* 872 + * Probing and removing are invoked by hotplug events raised upon line card insertion and 873 + * removing. If probing procedure fails all data is cleared. However, hotplug event still 874 + * will be raised on line card removing and activate removing procedure. In this case there 875 + * is nothing to remove. 876 + */ 877 + if (!data->notifier || !data->notifier->handle) 878 + return 0; 879 + 880 + /* Clear event notification callback and handle. */ 881 + data->notifier->user_handler = NULL; 882 + data->notifier->handle = NULL; 913 883 914 884 /* Destroy static I2C device feeding by main power. */ 915 885 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs,