All of lore.kernel.org
 help / color / mirror / Atom feed
From: Francesco Lavra <francescolavra.fl@gmail.com>
To: Rajanikanth H V <rajanikanth.hv@linaro.org>
Cc: rob.herring@calxeda.com, 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,
	rajanikanth.hv@stericsson.com
Subject: Re: [PATCH 1/4] mfd: ab8500: add devicetree support for fuelgauge
Date: Sat, 10 Nov 2012 17:53:40 +0100	[thread overview]
Message-ID: <509E8694.7080609@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1211072354150.5888@ubuntu12>

On 11/07/2012 07:45 PM, Rajanikanth H V wrote:
> On Thu, 1 Nov 2012, Francesco Lavra wrote:
> [...]
>>> +    btech = of_get_property(np_bat_supply,
>>> +        "stericsson,battery-type", NULL);
>>> +    if (!btech) {
>>> +        dev_warn(dev, "missing property battery-name/type\n");
>>> +        strcpy(bat_tech, "UNKNOWN");
>>> +    } else {
>>> +        strcpy(bat_tech, btech);
>>> +    }
>>
>> I don't get the point of declaring the char array and copying the string
>> in it, when you could simply use just the pointer returned by
>> of_get_property().
> 
> I am considering a corner case where in 'battery-type' property is not
> present and battery is connected.In this case i promote battery to
> UNKNOWN from null.

You could achieve the same result without using the char array, with
this assignment:

btech = "UNKNOWN";

> FYI: Further, btemp driver will identify the connected battery based on
> resistance value and decide to use.
> Ref: ab8500_btemp_id(...) ab8500_btemp.c
> 
>> Anyway, if the string property is longer than 8 characters, you are
>> writing past the size of the destination array.
> 
> i believe it is safe as power_supply.h comprises defines having battery
> technology type in 4 characters length which is normally the case and
> 7 chars length being "UNKNOWN" seldom referred

You should be able to handle whatever the device tree contains, and if
it contains unexpected data this is not a good excuse for locking up the
system.

--
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, 10 Nov 2012 17:53:40 +0100	[thread overview]
Message-ID: <509E8694.7080609@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1211072354150.5888@ubuntu12>

On 11/07/2012 07:45 PM, Rajanikanth H V wrote:
> On Thu, 1 Nov 2012, Francesco Lavra wrote:
> [...]
>>> +    btech = of_get_property(np_bat_supply,
>>> +        "stericsson,battery-type", NULL);
>>> +    if (!btech) {
>>> +        dev_warn(dev, "missing property battery-name/type\n");
>>> +        strcpy(bat_tech, "UNKNOWN");
>>> +    } else {
>>> +        strcpy(bat_tech, btech);
>>> +    }
>>
>> I don't get the point of declaring the char array and copying the string
>> in it, when you could simply use just the pointer returned by
>> of_get_property().
> 
> I am considering a corner case where in 'battery-type' property is not
> present and battery is connected.In this case i promote battery to
> UNKNOWN from null.

You could achieve the same result without using the char array, with
this assignment:

btech = "UNKNOWN";

> FYI: Further, btemp driver will identify the connected battery based on
> resistance value and decide to use.
> Ref: ab8500_btemp_id(...) ab8500_btemp.c
> 
>> Anyway, if the string property is longer than 8 characters, you are
>> writing past the size of the destination array.
> 
> i believe it is safe as power_supply.h comprises defines having battery
> technology type in 4 characters length which is normally the case and
> 7 chars length being "UNKNOWN" seldom referred

You should be able to handle whatever the device tree contains, and if
it contains unexpected data this is not a good excuse for locking up the
system.

--
Francesco

  reply	other threads:[~2012-11-10 16:53 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-31 15:40 [PATCH 0/4] Implement device tree support for ab8500 BM Devices Rajanikanth H.V
2012-10-31 15:40 ` 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 [this message]
2012-11-10 16:53         ` Francesco Lavra
2012-11-15 11:34         ` Rajanikanth HV
2012-11-15 11:34           ` Rajanikanth HV
2012-10-31 15:40 ` [PATCH 2/4] mfd: ab8500: add devicetree support for btemp Rajanikanth H.V
2012-10-31 15:40   ` Rajanikanth H.V
2012-10-31 15:40 ` [PATCH 3/4] mfd: ab8500: add devicetree support for charger Rajanikanth H.V
2012-10-31 15:40   ` Rajanikanth H.V
2012-10-31 15:40 ` [PATCH 4/4] mfd: ab8500: add devicetree support for chargalg Rajanikanth H.V
2012-10-31 15:40   ` Rajanikanth H.V
2012-11-19  3:46 ` [PATCH 0/4] Implement device tree support for ab8500 BM Devices Anton Vorontsov
2012-11-19  3:46   ` Anton Vorontsov
2012-11-19  3:58   ` Rajanikanth HV
2012-11-19  3:58     ` Rajanikanth HV
2012-11-19  4:57     ` Anton Vorontsov
2012-11-19  4:57       ` Anton Vorontsov
  -- strict thread matches above, loose matches on Subject: below --
2012-11-22 18:43 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
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-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
2012-10-06 14:01     ` Francesco Lavra

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=509E8694.7080609@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@linaro.org \
    --cc=rajanikanth.hv@stericsson.com \
    --cc=rob.herring@calxeda.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: link
Be 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.