All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single()
@ 2023-03-24 11:41 Andy Shevchenko
  2023-03-27  9:53 ` Sakari Ailus
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2023-03-24 11:41 UTC (permalink / raw)
  To: Rafael J. Wysocki, Sakari Ailus, linux-acpi, linux-kernel
  Cc: Rafael J. Wysocki, Len Brown, Andy Shevchenko

Refactor acpi_data_prop_read_single() for decreased indentation
and better structure. No functional changes intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/property.c | 80 ++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 46 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index b8d9eb9a433e..413e4fcadcaf 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -971,60 +971,48 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
 				      enum dev_prop_type proptype, void *val)
 {
 	const union acpi_object *obj;
-	int ret;
+	int ret = 0;
 
-	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
+	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64)
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
-		if (ret)
-			return ret;
-
-		switch (proptype) {
-		case DEV_PROP_U8:
-			if (obj->integer.value > U8_MAX)
-				return -EOVERFLOW;
-
-			if (val)
-				*(u8 *)val = obj->integer.value;
-
-			break;
-		case DEV_PROP_U16:
-			if (obj->integer.value > U16_MAX)
-				return -EOVERFLOW;
-
-			if (val)
-				*(u16 *)val = obj->integer.value;
-
-			break;
-		case DEV_PROP_U32:
-			if (obj->integer.value > U32_MAX)
-				return -EOVERFLOW;
-
-			if (val)
-				*(u32 *)val = obj->integer.value;
-
-			break;
-		default:
-			if (val)
-				*(u64 *)val = obj->integer.value;
-
-			break;
-		}
-
-		if (!val)
-			return 1;
-	} else if (proptype == DEV_PROP_STRING) {
+	else if (proptype == DEV_PROP_STRING)
 		ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj);
-		if (ret)
-			return ret;
+	if (ret)
+		return ret;
 
+	switch (proptype) {
+	case DEV_PROP_U8:
+		if (obj->integer.value > U8_MAX)
+			return -EOVERFLOW;
+		if (val)
+			*(u8 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_U16:
+		if (obj->integer.value > U16_MAX)
+			return -EOVERFLOW;
+		if (val)
+			*(u16 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_U32:
+		if (obj->integer.value > U32_MAX)
+			return -EOVERFLOW;
+		if (val)
+			*(u32 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_U64:
+		if (val)
+			*(u64 *)val = obj->integer.value;
+		break;
+	case DEV_PROP_STRING:
 		if (val)
 			*(char **)val = obj->string.pointer;
-
 		return 1;
-	} else {
-		ret = -EINVAL;
+	default:
+		return -EINVAL;
 	}
-	return ret;
+
+	/* When no storage provided return number of available values */
+	return val ? 0 : 1;
 }
 
 #define acpi_copy_property_array_uint(items, val, nval)			\
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single()
  2023-03-24 11:41 [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single() Andy Shevchenko
@ 2023-03-27  9:53 ` Sakari Ailus
  2023-03-27 18:49   ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Sakari Ailus @ 2023-03-27  9:53 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rafael J. Wysocki, linux-acpi, linux-kernel, Rafael J. Wysocki,
	Len Brown

Hi Andy,

Thanks for the patch.

On Fri, Mar 24, 2023 at 01:41:46PM +0200, Andy Shevchenko wrote:
> Refactor acpi_data_prop_read_single() for decreased indentation
> and better structure. No functional changes intended.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single()
  2023-03-27  9:53 ` Sakari Ailus
@ 2023-03-27 18:49   ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2023-03-27 18:49 UTC (permalink / raw)
  To: Sakari Ailus, Andy Shevchenko
  Cc: Rafael J. Wysocki, linux-acpi, linux-kernel, Rafael J. Wysocki,
	Len Brown

On Mon, Mar 27, 2023 at 11:54 AM Sakari Ailus
<sakari.ailus@linux.intel.com> wrote:
>
> Hi Andy,
>
> Thanks for the patch.
>
> On Fri, Mar 24, 2023 at 01:41:46PM +0200, Andy Shevchenko wrote:
> > Refactor acpi_data_prop_read_single() for decreased indentation
> > and better structure. No functional changes intended.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Applied as 6.4 material, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single()
@ 2023-03-26 15:29 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2023-03-26 15:29 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20230324114146.4037-1-andriy.shevchenko@linux.intel.com>
References: <20230324114146.4037-1-andriy.shevchenko@linux.intel.com>
TO: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
TO: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
TO: Sakari Ailus <sakari.ailus@linux.intel.com>
TO: linux-acpi@vger.kernel.org
TO: linux-kernel@vger.kernel.org
CC: Len Brown <lenb@kernel.org>
CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on sailus-media-tree/streams linus/master v6.3-rc3 next-20230324]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/ACPI-property-Refactor-acpi_data_prop_read_single/20230324-194227
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20230324114146.4037-1-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single()
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20230326/202303262312.a3ISTjXP-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Link: https://lore.kernel.org/r/202303262312.a3ISTjXP-lkp@intel.com/

New smatch warnings:
drivers/acpi/property.c:985 acpi_data_prop_read_single() error: potentially dereferencing uninitialized 'obj'.

Old smatch warnings:
drivers/acpi/property.c:991 acpi_data_prop_read_single() error: potentially dereferencing uninitialized 'obj'.
drivers/acpi/property.c:997 acpi_data_prop_read_single() error: potentially dereferencing uninitialized 'obj'.
drivers/acpi/property.c:1004 acpi_data_prop_read_single() error: potentially dereferencing uninitialized 'obj'.

vim +/obj +985 drivers/acpi/property.c

b31384fa5de37a Rafael J. Wysocki 2014-11-04   968  
99a85464693faa Sakari Ailus      2017-07-21   969  static int acpi_data_prop_read_single(const struct acpi_device_data *data,
3a7a2ab839ad18 Rafael J. Wysocki 2015-08-27   970  				      const char *propname,
b31384fa5de37a Rafael J. Wysocki 2014-11-04   971  				      enum dev_prop_type proptype, void *val)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   972  {
b31384fa5de37a Rafael J. Wysocki 2014-11-04   973  	const union acpi_object *obj;
b7de12063ff88b Andy Shevchenko   2023-03-24   974  	int ret = 0;
b31384fa5de37a Rafael J. Wysocki 2014-11-04   975  
b7de12063ff88b Andy Shevchenko   2023-03-24   976  	if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64)
3a7a2ab839ad18 Rafael J. Wysocki 2015-08-27   977  		ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
b7de12063ff88b Andy Shevchenko   2023-03-24   978  	else if (proptype == DEV_PROP_STRING)
b7de12063ff88b Andy Shevchenko   2023-03-24   979  		ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj);
b31384fa5de37a Rafael J. Wysocki 2014-11-04   980  	if (ret)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   981  		return ret;
b31384fa5de37a Rafael J. Wysocki 2014-11-04   982  
b31384fa5de37a Rafael J. Wysocki 2014-11-04   983  	switch (proptype) {
b31384fa5de37a Rafael J. Wysocki 2014-11-04   984  	case DEV_PROP_U8:
b31384fa5de37a Rafael J. Wysocki 2014-11-04  @985  		if (obj->integer.value > U8_MAX)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   986  			return -EOVERFLOW;
e1e6bd2995ac0e Rafael J. Wysocki 2021-02-11   987  		if (val)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   988  			*(u8 *)val = obj->integer.value;
b31384fa5de37a Rafael J. Wysocki 2014-11-04   989  		break;
b31384fa5de37a Rafael J. Wysocki 2014-11-04   990  	case DEV_PROP_U16:
b31384fa5de37a Rafael J. Wysocki 2014-11-04   991  		if (obj->integer.value > U16_MAX)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   992  			return -EOVERFLOW;
e1e6bd2995ac0e Rafael J. Wysocki 2021-02-11   993  		if (val)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   994  			*(u16 *)val = obj->integer.value;
b31384fa5de37a Rafael J. Wysocki 2014-11-04   995  		break;
b31384fa5de37a Rafael J. Wysocki 2014-11-04   996  	case DEV_PROP_U32:
b31384fa5de37a Rafael J. Wysocki 2014-11-04   997  		if (obj->integer.value > U32_MAX)
b31384fa5de37a Rafael J. Wysocki 2014-11-04   998  			return -EOVERFLOW;
e1e6bd2995ac0e Rafael J. Wysocki 2021-02-11   999  		if (val)
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1000  			*(u32 *)val = obj->integer.value;
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1001  		break;
b7de12063ff88b Andy Shevchenko   2023-03-24  1002  	case DEV_PROP_U64:
e1e6bd2995ac0e Rafael J. Wysocki 2021-02-11  1003  		if (val)
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1004  			*(u64 *)val = obj->integer.value;
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1005  		break;
b7de12063ff88b Andy Shevchenko   2023-03-24  1006  	case DEV_PROP_STRING:
e1e6bd2995ac0e Rafael J. Wysocki 2021-02-11  1007  		if (val)
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1008  			*(char **)val = obj->string.pointer;
b0b027cee090a1 Sakari Ailus      2017-03-28  1009  		return 1;
b7de12063ff88b Andy Shevchenko   2023-03-24  1010  	default:
b7de12063ff88b Andy Shevchenko   2023-03-24  1011  		return -EINVAL;
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1012  	}
b7de12063ff88b Andy Shevchenko   2023-03-24  1013  
b7de12063ff88b Andy Shevchenko   2023-03-24  1014  	/* When no storage provided return number of available values */
b7de12063ff88b Andy Shevchenko   2023-03-24  1015  	return val ? 0 : 1;
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1016  }
b31384fa5de37a Rafael J. Wysocki 2014-11-04  1017  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-27 18:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 11:41 [PATCH v1 1/1] ACPI: property: Refactor acpi_data_prop_read_single() Andy Shevchenko
2023-03-27  9:53 ` Sakari Ailus
2023-03-27 18:49   ` Rafael J. Wysocki
2023-03-26 15:29 kernel test robot

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.