2021-05-07 16:51:01

by Wei Ming Chen

[permalink] [raw]
Subject: [PATCH] power: supply: oplc_battery: Use fallthrough pseudo-keyword

Add pseudo-keyword macro fallthrough[1]

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Wei Ming Chen <[email protected]>
---
drivers/power/supply/olpc_battery.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c
index e0476ec06601..743b7f1cf9ea 100644
--- a/drivers/power/supply/olpc_battery.c
+++ b/drivers/power/supply/olpc_battery.c
@@ -238,6 +238,7 @@ static int olpc_bat_get_charge_full_design(union power_supply_propval *val)
case POWER_SUPPLY_TECHNOLOGY_LiFe:
switch (mfr) {
case 1: /* Gold Peak, fall through */
+ fallthrough;
case 2: /* BYD */
val->intval = 2800000;
break;
--
2.25.1


2021-06-04 11:58:23

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH] power: supply: oplc_battery: Use fallthrough pseudo-keyword

[+cc Kees and Gustavo]

Hi,

On Fri, May 07, 2021 at 08:47:24PM +0800, Wei Ming Chen wrote:
> Add pseudo-keyword macro fallthrough[1]
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through
>
> Signed-off-by: Wei Ming Chen <[email protected]>
> ---

I suppose completely empty case branch is also ok and just not
documented? I mean it does not hurt much in this case, but quite
a few power-supply drivers have something like this and it would
IMHO reduce readability to add fallthrough; to all of them.

property_is_writable(dev, prop) {
switch (prop) {
case A:
case C:
case E:
return true;
default:
return false;
}
}

Thanks,

-- Sebastian

> drivers/power/supply/olpc_battery.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c
> index e0476ec06601..743b7f1cf9ea 100644
> --- a/drivers/power/supply/olpc_battery.c
> +++ b/drivers/power/supply/olpc_battery.c
> @@ -238,6 +238,7 @@ static int olpc_bat_get_charge_full_design(union power_supply_propval *val)
> case POWER_SUPPLY_TECHNOLOGY_LiFe:
> switch (mfr) {
> case 1: /* Gold Peak, fall through */
> + fallthrough;
> case 2: /* BYD */
> val->intval = 2800000;
> break;
> --
> 2.25.1
>


Attachments:
(No filename) (1.41 kB)
signature.asc (849.00 B)
Download all attachments

2021-06-04 12:16:48

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH] power: supply: oplc_battery: Use fallthrough pseudo-keyword



On 6/4/21 06:54, Sebastian Reichel wrote:
> [+cc Kees and Gustavo]
>
> Hi,
>
> On Fri, May 07, 2021 at 08:47:24PM +0800, Wei Ming Chen wrote:
>> Add pseudo-keyword macro fallthrough[1]
>>
>> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through
>>
>> Signed-off-by: Wei Ming Chen <[email protected]>
>> ---
>
> I suppose completely empty case branch is also ok and just not
> documented? I mean it does not hurt much in this case, but quite

Exactly; it's not documented because it doesn't need to be marked
with fallthrough; :)

Not sure what was the motivation for this patch.

--
Gustavo

> a few power-supply drivers have something like this and it would
> IMHO reduce readability to add fallthrough; to all of them.
>
> property_is_writable(dev, prop) {
> switch (prop) {
> case A:
> case C:
> case E:
> return true;
> default:
> return false;
> }
> }
>
> Thanks,
>
> -- Sebastian
>
>> drivers/power/supply/olpc_battery.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c
>> index e0476ec06601..743b7f1cf9ea 100644
>> --- a/drivers/power/supply/olpc_battery.c
>> +++ b/drivers/power/supply/olpc_battery.c
>> @@ -238,6 +238,7 @@ static int olpc_bat_get_charge_full_design(union power_supply_propval *val)
>> case POWER_SUPPLY_TECHNOLOGY_LiFe:
>> switch (mfr) {
>> case 1: /* Gold Peak, fall through */
>> + fallthrough;
>> case 2: /* BYD */
>> val->intval = 2800000;
>> break;
>> --
>> 2.25.1
>>