extcon: Make static analyzer happy about union assignment
PATCH 1/7 extcon: Make static analyzer happy about union assignment
When assign unions we need to supply non-scalar value, otherwise static analyzer is not happy:
CHECK drivers/extcon/extcon.cdrivers/extcon/extcon.c:631:22: warning: cast to non-scalar
--- drivers/extcon/extcon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon.c +1 -1
@@ -628,7 +628,7 @@ int extcon_get_property(struct extcon_dev *edev, unsigned int id,unsigned long flags;int index, ret =0 ; - *prop_val = (union extcon_property_value )(0 ); + *prop_val = (union extcon_property_value ){0 };if (!edev)return -EINVAL ;
Signature · 1 line
2.18.0
PATCH 2/7 extcon: Switch to use kasprintf() instead of open coded
Switch to use kasprintf() instead of open coded variant. No functional change intended.
--- drivers/extcon/extcon.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/extcon/extcon.c +3 -10
@@ -1123,7 +1123,6 @@ int extcon_dev_register(struct extcon_dev *edev) (unsigned long)atomic_inc_return(&edev_no));if (edev->max_supported) { -char buf[10 ];char *str;struct extcon_cable *cable;
@@ -1137,9 +1136,7 @@ int extcon_dev_register(struct extcon_dev *edev)for (index =0 ; index < edev->max_supported; index++) { cable = &edev->cables[index]; -snprintf (buf,10 ,"cable.%d" , index); - str =kzalloc (strlen (buf) +1 , -GFP_KERNEL ); + str =kasprintf (GFP_KERNEL ,"cable.%d" , index);if (!str) {for (index--; index >=0 ; index--) { cable = &edev->cables[index];
@@ -1149,7 +1146,6 @@ int extcon_dev_register(struct extcon_dev *edev) goto err_alloc_cables; } -strcpy (str, buf); cable->edev = edev; cable->cable_index = index;
@@ -1172,7 +1168,6 @@ int extcon_dev_register(struct extcon_dev *edev) }if (edev->max_supported && edev->mutually_exclusive) { -char buf[80 ];char *name;/* Count the size of mutually_exclusive array */
@@ -1197,9 +1192,8 @@ int extcon_dev_register(struct extcon_dev *edev) }for (index =0 ; edev->mutually_exclusive[index]; index++) { -sprintf (buf,"0x%x" , edev->mutually_exclusive[index]); - name =kzalloc (strlen (buf) +1 , -GFP_KERNEL ); + name =kasprintf (GFP_KERNEL ,"0x%x" , + edev->mutually_exclusive[index]);if (!name) {for (index--; index >=0 ; index--) { kfree(edev->d_attrs_muex[index].attr.
@@ -1210,7 +1204,6 @@ int extcon_dev_register(struct extcon_dev *edev) ret = -ENOMEM ; goto err_muex; } -strcpy (name, buf);sysfs_attr_init (&edev->d_attrs_muex[index].attr); edev->d_attrs_muex[index].attr.name = name; edev->d_attrs_muex[index].attr.mode =0000 ;
Signature · 1 line
2.18.0
RE: [PATCH v1 2/7] extcon: Switch to use kasprintf() instead of open coded
From: Andy Shevchenko
Quoted 23 lines
Sent: 27 August 2018 16:36
Switch to use
kasprintf()instead of open coded variant. No functional change intended.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/extcon/extcon.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/extcon/extcon.c +0
-1@@ -1123,7 +1123,6 @@ int extcon_dev_register(struct extcon_dev *edev) (unsigned long)atomic_inc_return(&edev_no));if (edev->max_supported) { -char buf[10 ];char *str;struct extcon_cable *cable;
drivers/extcon/extcon.c int extcon_dev_register(struct extcon_dev *edev) · line 1139
Quoted 7 lines
drivers/extcon/extcon.c +1
-3@@ -1137,9 +1136,7 @@ int extcon_dev_register(struct extcon_dev *edev)for (index =0 ; index < edev->max_supported; index++) { cable = &edev->cables[index]; -snprintf (buf,10 ,"cable.%d" , index); - str =kzalloc (strlen (buf) +1 , -GFP_KERNEL ); + str =kasprintf (GFP_KERNEL ,"cable.%d" , index);
Hmmm... Why now just allocate the space for the string in the 'extcon_cable' structure.
(Then work out how to stop gcc complaining there isn't room for 4G cables ...)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
PATCH 3/7 extcon: cht-wc: Return from default case to avoid warnings
In reply to Andy ShevchenkoWhen we have first case to fall through it's not enough to put single comment there to satisfy compiler. Instead of doing that, return fall back value directly from default case.
This to avoid following warnings:
drivers/extcon/extcon-intel-cht-wc.c: In function ‘cht_wc_extcon_get_charger’:include/linux/device.h:1420:2: warning: this statement may fall through [-Wimplicit-fallthrough=]
_dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drivers/extcon/extcon-intel-cht-wc.c:148:3: note: in expansion of macro ‘dev_warn’
dev_warn(ext->dev,
^~~~~~~~drivers/extcon/extcon-intel-cht-wc.c:152:2: note: here
case CHT_WC_USBSRC_TYPE_SDP:
^~~~
--- drivers/extcon/extcon-intel-cht-wc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon-intel-cht-wc.c +1 -1
@@ -156,7 +156,7 @@ static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext,dev_warn (ext->dev,"Unhandled charger type %d, defaulting to SDP\n" , ret); -/* Fall through, treat as SDP */ +return EXTCON_CHG_USB_SDP ;case CHT_WC_USBSRC_TYPE_SDP :case CHT_WC_USBSRC_TYPE_FLOAT_DP_DN :case CHT_WC_USBSRC_TYPE_OTHER :
Signature · 1 line
2.18.0
PATCH 4/7 extcon: cht-wc: Fix definition names according to spec
In reply to Andy ShevchenkoThere is no suffix MASK in the spec and other small spelling fixes.
--- drivers/extcon/extcon-intel-cht-wc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +8 -8
@@ -32,10 +32,10 @@#define CHT_WC_CHGRCTRL0_EMRGCHREN BIT(1)#define CHT_WC_CHGRCTRL0_EXTCHRDIS BIT(2)#define CHT_WC_CHGRCTRL0_SWCONTROL BIT(3) -#define CHT_WC_CHGRCTRL0_TTLCK_MASK BIT(4) -#define CHT_WC_CHGRCTRL0_CCSM_OFF_MASK BIT(5) -#define CHT_WC_CHGRCTRL0_DBPOFF_MASK BIT(6) -#define CHT_WC_CHGRCTRL0_WDT_NOKICK BIT(7) +#define CHT_WC_CHGRCTRL0_TTLCK BIT(4) +#define CHT_WC_CHGRCTRL0_CCSM_OFF BIT(5) +#define CHT_WC_CHGRCTRL0_DBPOFF BIT(6) +#define CHT_WC_CHGRCTRL0_CHR_WDT_NOKICK BIT(7)#define CHT_WC_CHGRCTRL1 0x5e17
@@ -52,7 +52,7 @@#define CHT_WC_USBSRC_TYPE_ACA 4#define CHT_WC_USBSRC_TYPE_SE1 5#define CHT_WC_USBSRC_TYPE_MHL 6 -#define CHT_WC_USBSRC_TYPE_FLOAT_DP_DN 7 +#define CHT_WC_USBSRC_TYPE_FLOATING 7#define CHT_WC_USBSRC_TYPE_OTHER 8#define CHT_WC_USBSRC_TYPE_DCP_EXTPHY 9
@@ -61,7 +61,7 @@#define CHT_WC_PWRSRC_STS 0x6e1e#define CHT_WC_PWRSRC_VBUS BIT(0)#define CHT_WC_PWRSRC_DC BIT(1) -#define CHT_WC_PWRSRC_BAT BIT(2) +#define CHT_WC_PWRSRC_BATT BIT(2)#define CHT_WC_PWRSRC_ID_GND BIT(3)#define CHT_WC_PWRSRC_ID_FLOAT BIT(4)
@@ -158,7 +158,7 @@ static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext, ret);return EXTCON_CHG_USB_SDP ;case CHT_WC_USBSRC_TYPE_SDP : -case CHT_WC_USBSRC_TYPE_FLOAT_DP_DN : +case CHT_WC_USBSRC_TYPE_FLOATING :case CHT_WC_USBSRC_TYPE_OTHER :return EXTCON_CHG_USB_SDP ;case CHT_WC_USBSRC_TYPE_CDP :
@@ -279,7 +279,7 @@ static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable) {int ret, mask, val; - mask =CHT_WC_CHGRCTRL0_SWCONTROL |CHT_WC_CHGRCTRL0_CCSM_OFF_MASK ; + mask =CHT_WC_CHGRCTRL0_SWCONTROL |CHT_WC_CHGRCTRL0_CCSM_OFF ; val = enable ? mask :0 ; ret =regmap_update_bits (ext->regmap,CHT_WC_CHGRCTRL0 , mask, val);if (ret)
Signature · 1 line
2.18.0
PATCH 5/7 extcon: cht-wc: Correct USBID bit field handling
In reply to Andy ShevchenkoUSBID is 2-bit bit field according to specification. Make it clear.
No functional change intended.
--- drivers/extcon/extcon-intel-cht-wc.c | 32 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +19 -13
@@ -62,8 +62,11 @@#define CHT_WC_PWRSRC_VBUS BIT(0)#define CHT_WC_PWRSRC_DC BIT(1)#define CHT_WC_PWRSRC_BATT BIT(2) -#define CHT_WC_PWRSRC_ID_GND BIT(3) -#define CHT_WC_PWRSRC_ID_FLOAT BIT(4) +#define CHT_WC_PWRSRC_USBID_MASK GENMASK(4, 3) +#define CHT_WC_PWRSRC_USBID_SHIFT 3 +#define CHT_WC_PWRSRC_RID_ACA 0 +#define CHT_WC_PWRSRC_RID_GND 1 +#define CHT_WC_PWRSRC_RID_FLOAT 2#define CHT_WC_VBUS_GPIO_CTLO 0x6e2d#define CHT_WC_VBUS_GPIO_CTLO_OUTPUT BIT(0)
@@ -104,16 +107,20 @@ struct cht_wc_extcon_data {static int cht_wc_extcon_get_id (struct cht_wc_extcon_data *ext,int pwrsrc_sts) { -if (pwrsrc_sts &CHT_WC_PWRSRC_ID_GND ) +switch ((pwrsrc_sts &CHT_WC_PWRSRC_USBID_MASK ) >>CHT_WC_PWRSRC_USBID_SHIFT ) { +case CHT_WC_PWRSRC_RID_GND :return USB_ID_GND ; -if (pwrsrc_sts &CHT_WC_PWRSRC_ID_FLOAT ) +case CHT_WC_PWRSRC_RID_FLOAT :return USB_ID_FLOAT ; - -/* -* Once we have iio support for the gpadc we should read the USBID -* gpadc channel here and determine ACA role based on that. -*/ -return USB_ID_FLOAT ; +case CHT_WC_PWRSRC_RID_ACA : +default : +/* +* Once we have IIO support for the GPADC we should read +* the USBID GPADC channel here and determine ACA role +* based on that. +*/ +return USB_ID_FLOAT ; + } } static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext,
@@ -292,6 +299,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) {struct intel_soc_pmic *pmic =dev_get_drvdata (pdev->dev.parent);struct cht_wc_extcon_data *ext; +unsigned long mask = ~(CHT_WC_PWRSRC_VBUS |CHT_WC_PWRSRC_USBID_MASK );int irq, ret; irq =platform_get_irq (pdev,0 );
@@ -352,9 +360,7 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) }/* Unmask irqs */ - ret =regmap_write (ext->regmap,CHT_WC_PWRSRC_IRQ_MASK , - (int )~(CHT_WC_PWRSRC_VBUS |CHT_WC_PWRSRC_ID_GND | -CHT_WC_PWRSRC_ID_FLOAT )); + ret =regmap_write (ext->regmap,CHT_WC_PWRSRC_IRQ_MASK , mask);if (ret) {dev_err (ext->dev,"Error writing irq-mask: %d\n" , ret); goto disable_sw_control;
Signature · 1 line
2.18.0
PATCH 6/7 extcon: cht-wc: Convert to use SPDX identifier
In reply to Andy ShevchenkoConvert driver to use SPDX identifier.
--- drivers/extcon/extcon-intel-cht-wc.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/extcon/extcon-intel-cht-wc.c +1 -9
@@ -1,18 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Extcon charger detection driver for Intel Cherrytrail Whiskey Cove PMIC * Copyright (C) 2017 Hans de Goede <[email protected]> * * Based on various non upstream patches to support the CHT Whiskey Cove PMIC: * Copyright (C) 2013-2015 Intel Corporation. All rights reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. */ #include <linux/extcon-provider.h>
Signature · 1 line
2.18.0
PATCH 7/7 extcon: int3496: Convert to use SPDX identifier
In reply to Andy ShevchenkoConvert driver to use SPDX identifier.
While here, fix MODULE_LICENSE() string to be the same as license text states.
--- drivers/extcon/extcon-intel-int3496.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/extcon/extcon-intel-int3496.c +2 -10
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Intel INT3496 ACPI device extcon driver *
@@ -7,15 +8,6 @@* * Copyright (c) 2014, Intel Corporation. * Author: David Cohen <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. */ #include <linux/acpi.h>
@@ -192,4 +184,4 @@ module_platform_driver(int3496_driver);MODULE_AUTHOR ("Hans de Goede <[email protected]>" );MODULE_DESCRIPTION ("Intel INT3496 ACPI device extcon driver" ); -MODULE_LICENSE ("GPL" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.18.0
Hi,
Quoted 17 lines · Andy Shevchenko
When assign unions we need to supply non-scalar value, otherwise static analyzer is not happy:
CHECK
drivers/extcon/extcon.cdrivers/extcon/extcon.c:631:22: warning: cast to non-scalarSigned-off-by Andy Shevchenko <[email protected]>--- drivers/extcon/extcon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/extcon/extcon.c +0
-0
drivers/extcon/extcon.c int extcon_get_property(struct extcon_dev *edev, unsigned int id, · line 634
Quoted 8 lines
drivers/extcon/extcon.c +1
-1@@ -628,7 +628,7 @@ int extcon_get_property(struct extcon_dev *edev, unsigned int id,unsigned long flags;int index, ret =0 ; - *prop_val = (union extcon_property_value )(0 ); + *prop_val = (union extcon_property_value ){0 };if (!edev)return -EINVAL ;
Applied all patches of this series. Thanks.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics