From: Francesco Lavra <francescolavra.fl@gmail.com> To: "Rajanikanth H.V" <rajanikanth.hv@stericsson.com> Cc: lee.jones@linaro.org, arnd@arndb.de, anton.vorontsov@linaro.org, linus.walleij@stericsson.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, patches@linaro.org, STEricsson_nomadik_linux@list.st.com Subject: Re: [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge Date: Sat, 06 Oct 2012 16:01:53 +0200 [thread overview] Message-ID: <507039D1.3010307@gmail.com> (raw) In-Reply-To: <1349064513-31301-2-git-send-email-rajanikanth.hv@stericsson.com> Hi, On 10/01/2012 06:08 AM, Rajanikanth H.V wrote: > From: "Rajanikanth H.V" <rajanikanth.hv@stericsson.com> > > - This patch adds device tree support for fuelguage driver > - optimize bm devices platform_data usage and of_probe(...) > Note: of_probe() routine for battery managed devices is made > common across all bm drivers. [...] > +int __devinit > +bmdevs_of_probe(struct device *dev, > + struct device_node *np, > + struct abx500_bm_plat_data *pdata) > +{ > + int i, ret = 0, thermistor = NTC_INTERNAL; > + const __be32 *ph; > + const char *bat_tech; > + struct abx500_bm_data *bat; > + struct abx500_battery_type *btype; > + struct device_node *np_bat_supply; > + struct abx500_bmdevs_plat_data *plat_data = pdata->bmdev_pdata; > + > + /* get phandle to 'supplied-to' node */ > + ph = of_get_property(np, "supplied-to", &plat_data->num_supplicants); > + if (ph == NULL) { > + dev_err(dev, "no supplied_to property specified\n"); > + return -EINVAL; > + } > + plat_data->num_supplicants /= sizeof(int); > + plat_data->supplied_to = > + devm_kzalloc(dev, plat_data->num_supplicants * > + sizeof(const char *), GFP_KERNEL); > + if (plat_data->supplied_to == NULL) { > + dev_err(dev, "%s no mem for supplied-to\n", __func__); > + return -ENOMEM; > + } > + for (i = 0; i < plat_data->num_supplicants; ++i) { > + np_bat_supply = of_find_node_by_phandle(be32_to_cpup(ph) + i); > + if (np_bat_supply == NULL) { > + dev_err(dev, "invalid supplied_to property\n"); > + return -EINVAL; > + } > + ret = of_property_read_string(np_bat_supply, "interface-name", > + (const char **)(plat_data->supplied_to + i)); > + if (ret < 0) { > + of_node_put(np_bat_supply); > + dev_err(dev, "supply/interface name not found\n"); > + return ret; > + } If an error is encountered here, of_node_put() should be called for all nodes previously referenced with of_find_node_by_phandle (or of_parse_phandle, as Lee suggested). Also, if I'm not mistaken we have a leak here, because the refcount of these nodes is never decremented, not even in the driver remove routine. [...] > @@ -2446,18 +2444,47 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev) > { > int i, irq; > int ret = 0; > - struct abx500_bm_plat_data *plat_data = pdev->dev.platform_data; > + struct abx500_bm_plat_data *plat_data > + = pdev->dev.platform_data; > + struct device_node *np = pdev->dev.of_node; > struct ab8500_fg *di; > > + di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); > + if (!di) { > + dev_err(&pdev->dev, "%s no mem for ab8500_fg\n", __func__); > + return -ENOMEM; > + } > + if (np) { > + if (!plat_data) { > + plat_data = > + devm_kzalloc(&pdev->dev, sizeof(*plat_data), > + GFP_KERNEL); > + if (!plat_data) { > + dev_err(&pdev->dev, > + "%s no mem for plat_data\n", __func__); > + return -ENOMEM; > + } > + plat_data->bmdev_pdata = devm_kzalloc(&pdev->dev, > + sizeof(*plat_data->bmdev_pdata), GFP_KERNEL); > + if (!plat_data->bmdev_pdata) { > + dev_err(&pdev->dev, > + "%s no mem for pdata->fg\n", > + __func__); > + return -ENOMEM; > + } > + } > + ret = bmdevs_of_probe(&pdev->dev, np, plat_data); I think it's better to move allocation of bmdev_pdata and corresponding error check to bmdevs_of_probe(), because this code is shared by all battery management drivers. -- Francesco
WARNING: multiple messages have this Message-ID (diff)
From: francescolavra.fl@gmail.com (Francesco Lavra) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge Date: Sat, 06 Oct 2012 16:01:53 +0200 [thread overview] Message-ID: <507039D1.3010307@gmail.com> (raw) In-Reply-To: <1349064513-31301-2-git-send-email-rajanikanth.hv@stericsson.com> Hi, On 10/01/2012 06:08 AM, Rajanikanth H.V wrote: > From: "Rajanikanth H.V" <rajanikanth.hv@stericsson.com> > > - This patch adds device tree support for fuelguage driver > - optimize bm devices platform_data usage and of_probe(...) > Note: of_probe() routine for battery managed devices is made > common across all bm drivers. [...] > +int __devinit > +bmdevs_of_probe(struct device *dev, > + struct device_node *np, > + struct abx500_bm_plat_data *pdata) > +{ > + int i, ret = 0, thermistor = NTC_INTERNAL; > + const __be32 *ph; > + const char *bat_tech; > + struct abx500_bm_data *bat; > + struct abx500_battery_type *btype; > + struct device_node *np_bat_supply; > + struct abx500_bmdevs_plat_data *plat_data = pdata->bmdev_pdata; > + > + /* get phandle to 'supplied-to' node */ > + ph = of_get_property(np, "supplied-to", &plat_data->num_supplicants); > + if (ph == NULL) { > + dev_err(dev, "no supplied_to property specified\n"); > + return -EINVAL; > + } > + plat_data->num_supplicants /= sizeof(int); > + plat_data->supplied_to = > + devm_kzalloc(dev, plat_data->num_supplicants * > + sizeof(const char *), GFP_KERNEL); > + if (plat_data->supplied_to == NULL) { > + dev_err(dev, "%s no mem for supplied-to\n", __func__); > + return -ENOMEM; > + } > + for (i = 0; i < plat_data->num_supplicants; ++i) { > + np_bat_supply = of_find_node_by_phandle(be32_to_cpup(ph) + i); > + if (np_bat_supply == NULL) { > + dev_err(dev, "invalid supplied_to property\n"); > + return -EINVAL; > + } > + ret = of_property_read_string(np_bat_supply, "interface-name", > + (const char **)(plat_data->supplied_to + i)); > + if (ret < 0) { > + of_node_put(np_bat_supply); > + dev_err(dev, "supply/interface name not found\n"); > + return ret; > + } If an error is encountered here, of_node_put() should be called for all nodes previously referenced with of_find_node_by_phandle (or of_parse_phandle, as Lee suggested). Also, if I'm not mistaken we have a leak here, because the refcount of these nodes is never decremented, not even in the driver remove routine. [...] > @@ -2446,18 +2444,47 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev) > { > int i, irq; > int ret = 0; > - struct abx500_bm_plat_data *plat_data = pdev->dev.platform_data; > + struct abx500_bm_plat_data *plat_data > + = pdev->dev.platform_data; > + struct device_node *np = pdev->dev.of_node; > struct ab8500_fg *di; > > + di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); > + if (!di) { > + dev_err(&pdev->dev, "%s no mem for ab8500_fg\n", __func__); > + return -ENOMEM; > + } > + if (np) { > + if (!plat_data) { > + plat_data = > + devm_kzalloc(&pdev->dev, sizeof(*plat_data), > + GFP_KERNEL); > + if (!plat_data) { > + dev_err(&pdev->dev, > + "%s no mem for plat_data\n", __func__); > + return -ENOMEM; > + } > + plat_data->bmdev_pdata = devm_kzalloc(&pdev->dev, > + sizeof(*plat_data->bmdev_pdata), GFP_KERNEL); > + if (!plat_data->bmdev_pdata) { > + dev_err(&pdev->dev, > + "%s no mem for pdata->fg\n", > + __func__); > + return -ENOMEM; > + } > + } > + ret = bmdevs_of_probe(&pdev->dev, np, plat_data); I think it's better to move allocation of bmdev_pdata and corresponding error check to bmdevs_of_probe(), because this code is shared by all battery management drivers. -- Francesco
next prev parent reply other threads:[~2012-10-06 14:00 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-01 4:08 [PATCH 0/4] Implement device tree support for ab8500 BM Devices Rajanikanth H.V 2012-10-01 4:08 ` [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge Rajanikanth H.V 2012-10-01 9:49 ` Lee Jones 2012-10-01 9:49 ` Lee Jones 2012-10-01 9:59 ` Rajanikanth HV 2012-10-01 9:59 ` Rajanikanth HV 2012-10-01 10:36 ` Lee Jones 2012-10-01 10:36 ` Lee Jones 2012-10-01 10:22 ` Lee Jones 2012-10-01 10:22 ` Lee Jones 2012-10-06 14:01 ` Francesco Lavra [this message] 2012-10-06 14:01 ` Francesco Lavra 2012-10-01 4:08 ` [PATCH 2/4] mfd: ab8500: add devicetree support for Btemp Rajanikanth H.V 2012-10-01 4:08 ` [PATCH 3/4] mfd: ab8500: add devicetree support for charger Rajanikanth H.V 2012-10-01 4:08 ` [PATCH 4/4] mfd: ab8500: add devicetree support for charging algorithm Rajanikanth H.V 2012-10-25 6:30 [PATCH 0/4] Implement device tree support for ab8500 BM Devices Rajanikanth H.V 2012-10-25 6:30 ` [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge Rajanikanth H.V 2012-10-27 15:07 ` Francesco Lavra 2012-10-27 15:07 ` Francesco Lavra 2012-10-27 16:00 ` Rajanikanth HV 2012-10-27 16:00 ` Rajanikanth HV 2012-10-27 16:18 ` Francesco Lavra 2012-10-27 16:18 ` Francesco Lavra 2012-10-31 15:40 [PATCH 0/4] Implement device tree support for ab8500 BM Devices Rajanikanth H.V 2012-10-31 15:40 ` [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge Rajanikanth H.V 2012-10-31 15:40 ` Rajanikanth H.V 2012-11-01 15:15 ` Francesco Lavra 2012-11-01 15:15 ` Francesco Lavra 2012-11-07 18:45 ` Rajanikanth H V 2012-11-07 18:45 ` Rajanikanth H V 2012-11-10 16:53 ` Francesco Lavra 2012-11-10 16:53 ` Francesco Lavra 2012-11-15 11:34 ` Rajanikanth HV 2012-11-15 11:34 ` Rajanikanth HV 2012-11-22 18:43 [PATCH 0/4] Implement device tree support for ab8500 BM Devices Rajanikanth H.V 2012-11-22 18:43 ` [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge Rajanikanth H.V 2012-11-22 18:43 ` Rajanikanth H.V 2012-11-22 20:08 ` Anton Vorontsov 2012-11-22 20:08 ` Anton Vorontsov 2012-11-23 9:50 ` Lee Jones 2012-11-23 9:50 ` Lee Jones
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=507039D1.3010307@gmail.com \ --to=francescolavra.fl@gmail.com \ --cc=STEricsson_nomadik_linux@list.st.com \ --cc=anton.vorontsov@linaro.org \ --cc=arnd@arndb.de \ --cc=lee.jones@linaro.org \ --cc=linaro-dev@lists.linaro.org \ --cc=linus.walleij@stericsson.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=patches@linaro.org \ --cc=rajanikanth.hv@stericsson.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.