Message ID | 20190206051335.23799-1-bjorn.andersson@linaro.org |
---|---|
Headers | show |
Series | Qualcomm AOSS QMP driver and modem dts | expand |
Hi, On Tue, Feb 5, 2019 at 9:13 PM Bjorn Andersson <bjorn.andersson@linaro.org> wrote: > +static int qmp_pd_image_toggle(struct qmp_pd *res, bool enable) > +{ > + char buf[AOSS_QMP_PD_MSG_LEN]; > + > + memset(buf, 0, sizeof(buf)); Personally I find it safer/cleaner to do something like: char buf[AOSS_QMP_PD_MSG_LEN] = { }; ...but I won't insist. If you change this, change in qmp_pd_clock_toggle() too. > +static int qmp_pd_probe(struct platform_device *pdev) > +{ > + struct genpd_onecell_data *data; > + struct device *parent = pdev->dev.parent; > + struct qmp_pd *res; > + struct qmp *qmp; > + size_t num = ARRAY_SIZE(sdm845_resources); > + int ret; > + int i; > + > + qmp = dev_get_drvdata(pdev->dev.parent); > + if (!qmp) > + return -EINVAL; > + > + res = devm_kcalloc(&pdev->dev, num, sizeof(*res), GFP_KERNEL); > + if (!res) > + return -ENOMEM; > + > + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); > + if (!data) > + return -ENOMEM; > + > + data->domains = devm_kcalloc(&pdev->dev, num, sizeof(*data->domains), > + GFP_KERNEL); > + if (!data->domains) > + return -ENOMEM; > + > + for (i = 0; i < num; i++) { > + res[i].qmp = qmp; > + res[i].pd.name = sdm845_resources[i].name; > + res[i].pd.power_on = sdm845_resources[i].on; > + res[i].pd.power_off = sdm845_resources[i].off; > + > + ret = pm_genpd_init(&res[i].pd, NULL, true); > + if (ret < 0) { > + dev_err(&pdev->dev, "failed to init genpd\n"); It's often nice to print the error number (ret) in the message. > + goto unroll_genpds; > + } > + > + data->domains[i] = &res[i].pd; > + } > + > + data->num_domains = i; > + > + platform_set_drvdata(pdev, data); > + > + return of_genpd_add_provider_onecell(parent->of_node, data); Now that you have error handling (the calls to "pm_genpd_remove"), you can't just do this. You need: ret = of_genpd_add_provider_onecell(parent->of_node, data); if (!ret) return 0; > +unroll_genpds: > + for (i--; i >= 0; i--) > + pm_genpd_remove(data->domains[i]); > + > + return ret; > +} > + > +static int qmp_pd_remove(struct platform_device *pdev) > +{ > + struct device *parent = pdev->dev.parent; > + struct genpd_onecell_data *data = platform_get_drvdata(pdev); > + int i; > + > + of_genpd_del_provider(parent->of_node); > + > + for (i = 0; i < data->num_domains; i++) > + pm_genpd_remove(data->domains[i]); I presume it doesn't matter, but if you truly want to be the inverse of the "probe" then you'd want to iterate starting at "num_domains - 1" and go to 0. -Doug
Hi, On Tue, Feb 5, 2019 at 9:13 PM Bjorn Andersson <bjorn.andersson@linaro.org> wrote: > + if (of_property_read_bool(pdev->dev.of_node, "#power-domain-cells")) { > + qmp->pd_pdev = platform_device_register_data(&pdev->dev, > + "aoss_qmp_pd", > + PLATFORM_DEVID_NONE, > + NULL, 0); > + if (IS_ERR(qmp->pd_pdev)) { > + dev_err(&pdev->dev, "failed to register AOSS PD\n"); nit: not worth spinning just for this, but if you happen to spin you could print the error number in your message. > + ret = PTR_ERR(qmp->pd_pdev); > + goto err_close_qmp; > + } > + } As discussed in v5 I wonder if the complexity of a separate driver is really worth it or if everything would be a lot easier to just link the two ".c" files together. Now that it's a full error case if "aoss_qmp_pd" doesn't probe I'd vote for linking the two ".c" files together, but part of that is because I don't really want to dig into all the details of how you're supposed to call platform_device_register_data() for sub-devices and double-checking that you've got all the corner cases correct. ...NOTE: presumably if you just change it to a straight-up function call then you can also get rid of the above "dev_err" since (presumably) you'll know that the init code of aoss_qmp_pd will print any relevant errors? -Doug