2022-09-27 14:57:43

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 1/5] device property: Keep dev_fwnode() and dev_fwnode_const() separate

It's not fully correct to take a const parameter pointer to a struct
and return a non-const pointer to a member of that struct.

Instead, introduce a const version of the dev_fwnode() API which takes
and returns const pointers and use it where it's applicable.

Suggested-by: Sakari Ailus <[email protected]>
Fixes: aade55c86033 ("device property: Add const qualifier to device_get_match_data() parameter")
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/base/property.c | 11 +++++++++--
include/linux/property.h | 3 ++-
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 4d6278a84868..699f1b115e0a 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -17,13 +17,20 @@
#include <linux/property.h>
#include <linux/phy.h>

-struct fwnode_handle *dev_fwnode(const struct device *dev)
+struct fwnode_handle *dev_fwnode(struct device *dev)
{
return IS_ENABLED(CONFIG_OF) && dev->of_node ?
of_fwnode_handle(dev->of_node) : dev->fwnode;
}
EXPORT_SYMBOL_GPL(dev_fwnode);

+const struct fwnode_handle *dev_fwnode_const(const struct device *dev)
+{
+ return IS_ENABLED(CONFIG_OF) && dev->of_node ?
+ of_fwnode_handle(dev->of_node) : dev->fwnode;
+}
+EXPORT_SYMBOL_GPL(dev_fwnode_const);
+
/**
* device_property_present - check if a property of a device is present
* @dev: Device whose property is being checked
@@ -1202,7 +1209,7 @@ EXPORT_SYMBOL(fwnode_graph_parse_endpoint);

const void *device_get_match_data(const struct device *dev)
{
- return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
+ return fwnode_call_ptr_op(dev_fwnode_const(dev), device_get_match_data, dev);
}
EXPORT_SYMBOL_GPL(device_get_match_data);

diff --git a/include/linux/property.h b/include/linux/property.h
index 117cc200c656..ae5d7f8eccf4 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -32,7 +32,8 @@ enum dev_dma_attr {
DEV_DMA_COHERENT,
};

-struct fwnode_handle *dev_fwnode(const struct device *dev);
+struct fwnode_handle *dev_fwnode(struct device *dev);
+const struct fwnode_handle *dev_fwnode_const(const struct device *dev);

bool device_property_present(struct device *dev, const char *propname);
int device_property_read_u8_array(struct device *dev, const char *propname,
--
2.35.1


2022-09-27 15:21:31

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 2/5] device property: Constify fwnode connection match APIs

The fwnode and device parameters are not altered in the fwnode
connection match APIs, constify them.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/base/property.c | 8 ++++----
drivers/usb/roles/class.c | 2 +-
drivers/usb/typec/retimer.c | 2 +-
include/linux/property.h | 10 +++++-----
4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 699f1b115e0a..1a1616c9b599 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1213,7 +1213,7 @@ const void *device_get_match_data(const struct device *dev)
}
EXPORT_SYMBOL_GPL(device_get_match_data);

-static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode,
+static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwnode,
const char *con_id, void *data,
devcon_match_fn_t match,
void **matches,
@@ -1247,7 +1247,7 @@ static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode,
return count;
}

-static unsigned int fwnode_devcon_matches(struct fwnode_handle *fwnode,
+static unsigned int fwnode_devcon_matches(const struct fwnode_handle *fwnode,
const char *con_id, void *data,
devcon_match_fn_t match,
void **matches,
@@ -1289,7 +1289,7 @@ static unsigned int fwnode_devcon_matches(struct fwnode_handle *fwnode,
* device node. @match will be used to convert the connection description to
* data the caller is expecting to be returned.
*/
-void *fwnode_connection_find_match(struct fwnode_handle *fwnode,
+void *fwnode_connection_find_match(const struct fwnode_handle *fwnode,
const char *con_id, void *data,
devcon_match_fn_t match)
{
@@ -1326,7 +1326,7 @@ EXPORT_SYMBOL_GPL(fwnode_connection_find_match);
*
* Return: Number of matches resolved, or negative errno.
*/
-int fwnode_connection_find_matches(struct fwnode_handle *fwnode,
+int fwnode_connection_find_matches(const struct fwnode_handle *fwnode,
const char *con_id, void *data,
devcon_match_fn_t match,
void **matches, unsigned int matches_len)
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index dfaed7eee94f..a3575a5a18ce 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -87,7 +87,7 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
}
EXPORT_SYMBOL_GPL(usb_role_switch_get_role);

-static void *usb_role_switch_match(struct fwnode_handle *fwnode, const char *id,
+static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const char *id,
void *data)
{
struct device *dev;
diff --git a/drivers/usb/typec/retimer.c b/drivers/usb/typec/retimer.c
index 2003731f1bee..8edfdc709a28 100644
--- a/drivers/usb/typec/retimer.c
+++ b/drivers/usb/typec/retimer.c
@@ -34,7 +34,7 @@ static int retimer_fwnode_match(struct device *dev, const void *fwnode)
return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-retimer");
}

-static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data)
+static void *typec_retimer_match(const struct fwnode_handle *fwnode, const char *id, void *data)
{
struct device *dev;

diff --git a/include/linux/property.h b/include/linux/property.h
index ae5d7f8eccf4..6f9d6604edc3 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -438,21 +438,21 @@ unsigned int fwnode_graph_get_endpoint_count(struct fwnode_handle *fwnode,
int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
struct fwnode_endpoint *endpoint);

-typedef void *(*devcon_match_fn_t)(struct fwnode_handle *fwnode, const char *id,
+typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id,
void *data);

-void *fwnode_connection_find_match(struct fwnode_handle *fwnode,
+void *fwnode_connection_find_match(const struct fwnode_handle *fwnode,
const char *con_id, void *data,
devcon_match_fn_t match);

-static inline void *device_connection_find_match(struct device *dev,
+static inline void *device_connection_find_match(const struct device *dev,
const char *con_id, void *data,
devcon_match_fn_t match)
{
- return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match);
+ return fwnode_connection_find_match(dev_fwnode_const(dev), con_id, data, match);
}

-int fwnode_connection_find_matches(struct fwnode_handle *fwnode,
+int fwnode_connection_find_matches(const struct fwnode_handle *fwnode,
const char *con_id, void *data,
devcon_match_fn_t match,
void **matches, unsigned int matches_len);
--
2.35.1

2022-09-27 16:45:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] device property: Constify fwnode connection match APIs

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on driver-core/driver-core-testing]
[cannot apply to usb/usb-testing westeri-thunderbolt/next linus/master v6.0-rc7 next-20220923]
[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/device-property-Keep-dev_fwnode-and-dev_fwnode_const-separate/20220927-223109
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 1da40c2667388dd70306bfd3d4dcb49fd20b50a9
config: sh-allmodconfig
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/34401a778cc4e8ddd9610bf7f76d8b7e4fff142e
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andy-Shevchenko/device-property-Keep-dev_fwnode-and-dev_fwnode_const-separate/20220927-223109
git checkout 34401a778cc4e8ddd9610bf7f76d8b7e4fff142e
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash drivers/usb/typec/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

drivers/usb/typec/mux.c: In function 'fwnode_typec_switch_get':
>> drivers/usb/typec/mux.c:84:48: error: passing argument 4 of 'fwnode_connection_find_matches' from incompatible pointer type [-Werror=incompatible-pointer-types]
84 | typec_switch_match,
| ^~~~~~~~~~~~~~~~~~
| |
| void * (*)(struct fwnode_handle *, const char *, void *)
In file included from drivers/usb/typec/mux.c:14:
include/linux/property.h:457:54: note: expected 'devcon_match_fn_t' {aka 'void * (*)(const struct fwnode_handle *, const char *, void *)'} but argument is of type 'void * (*)(struct fwnode_handle *, const char *, void *)'
457 | devcon_match_fn_t match,
| ~~~~~~~~~~~~~~~~~~^~~~~
drivers/usb/typec/mux.c: In function 'fwnode_typec_mux_get':
drivers/usb/typec/mux.c:352:62: error: passing argument 4 of 'fwnode_connection_find_matches' from incompatible pointer type [-Werror=incompatible-pointer-types]
352 | (void *)desc, typec_mux_match,
| ^~~~~~~~~~~~~~~
| |
| void * (*)(struct fwnode_handle *, const char *, void *)
include/linux/property.h:457:54: note: expected 'devcon_match_fn_t' {aka 'void * (*)(const struct fwnode_handle *, const char *, void *)'} but argument is of type 'void * (*)(struct fwnode_handle *, const char *, void *)'
457 | devcon_match_fn_t match,
| ~~~~~~~~~~~~~~~~~~^~~~~
cc1: some warnings being treated as errors


vim +/fwnode_connection_find_matches +84 drivers/usb/typec/mux.c

bdecb33af34f79 Heikki Krogerus 2018-03-20 61
bdecb33af34f79 Heikki Krogerus 2018-03-20 62 /**
d1c6a769cdf466 Heikki Krogerus 2020-03-02 63 * fwnode_typec_switch_get - Find USB Type-C orientation switch
d1c6a769cdf466 Heikki Krogerus 2020-03-02 64 * @fwnode: The caller device node
bdecb33af34f79 Heikki Krogerus 2018-03-20 65 *
bdecb33af34f79 Heikki Krogerus 2018-03-20 66 * Finds a switch linked with @dev. Returns a reference to the switch on
bdecb33af34f79 Heikki Krogerus 2018-03-20 67 * success, NULL if no matching connection was found, or
bdecb33af34f79 Heikki Krogerus 2018-03-20 68 * ERR_PTR(-EPROBE_DEFER) when a connection was found but the switch
bdecb33af34f79 Heikki Krogerus 2018-03-20 69 * has not been enumerated yet.
bdecb33af34f79 Heikki Krogerus 2018-03-20 70 */
d1c6a769cdf466 Heikki Krogerus 2020-03-02 71 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
bdecb33af34f79 Heikki Krogerus 2018-03-20 72 {
71793b579ba682 Bjorn Andersson 2022-04-22 73 struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
bdecb33af34f79 Heikki Krogerus 2018-03-20 74 struct typec_switch *sw;
71793b579ba682 Bjorn Andersson 2022-04-22 75 int count;
71793b579ba682 Bjorn Andersson 2022-04-22 76 int err;
71793b579ba682 Bjorn Andersson 2022-04-22 77 int i;
bdecb33af34f79 Heikki Krogerus 2018-03-20 78
713fd49b430c37 Bjorn Andersson 2022-04-22 79 sw = kzalloc(sizeof(*sw), GFP_KERNEL);
713fd49b430c37 Bjorn Andersson 2022-04-22 80 if (!sw)
713fd49b430c37 Bjorn Andersson 2022-04-22 81 return ERR_PTR(-ENOMEM);
713fd49b430c37 Bjorn Andersson 2022-04-22 82
71793b579ba682 Bjorn Andersson 2022-04-22 83 count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
71793b579ba682 Bjorn Andersson 2022-04-22 @84 typec_switch_match,
71793b579ba682 Bjorn Andersson 2022-04-22 85 (void **)sw_devs,
71793b579ba682 Bjorn Andersson 2022-04-22 86 ARRAY_SIZE(sw_devs));
71793b579ba682 Bjorn Andersson 2022-04-22 87 if (count <= 0) {
713fd49b430c37 Bjorn Andersson 2022-04-22 88 kfree(sw);
71793b579ba682 Bjorn Andersson 2022-04-22 89 return NULL;
713fd49b430c37 Bjorn Andersson 2022-04-22 90 }
713fd49b430c37 Bjorn Andersson 2022-04-22 91
71793b579ba682 Bjorn Andersson 2022-04-22 92 for (i = 0; i < count; i++) {
71793b579ba682 Bjorn Andersson 2022-04-22 93 if (IS_ERR(sw_devs[i])) {
71793b579ba682 Bjorn Andersson 2022-04-22 94 err = PTR_ERR(sw_devs[i]);
71793b579ba682 Bjorn Andersson 2022-04-22 95 goto put_sw_devs;
71793b579ba682 Bjorn Andersson 2022-04-22 96 }
71793b579ba682 Bjorn Andersson 2022-04-22 97 }
713fd49b430c37 Bjorn Andersson 2022-04-22 98
71793b579ba682 Bjorn Andersson 2022-04-22 99 for (i = 0; i < count; i++) {
71793b579ba682 Bjorn Andersson 2022-04-22 100 WARN_ON(!try_module_get(sw_devs[i]->dev.parent->driver->owner));
71793b579ba682 Bjorn Andersson 2022-04-22 101 sw->sw_devs[i] = sw_devs[i];
71793b579ba682 Bjorn Andersson 2022-04-22 102 }
71793b579ba682 Bjorn Andersson 2022-04-22 103
71793b579ba682 Bjorn Andersson 2022-04-22 104 sw->num_sw_devs = count;
bdecb33af34f79 Heikki Krogerus 2018-03-20 105
bdecb33af34f79 Heikki Krogerus 2018-03-20 106 return sw;
71793b579ba682 Bjorn Andersson 2022-04-22 107
71793b579ba682 Bjorn Andersson 2022-04-22 108 put_sw_devs:
71793b579ba682 Bjorn Andersson 2022-04-22 109 for (i = 0; i < count; i++) {
71793b579ba682 Bjorn Andersson 2022-04-22 110 if (!IS_ERR(sw_devs[i]))
71793b579ba682 Bjorn Andersson 2022-04-22 111 put_device(&sw_devs[i]->dev);
71793b579ba682 Bjorn Andersson 2022-04-22 112 }
71793b579ba682 Bjorn Andersson 2022-04-22 113
71793b579ba682 Bjorn Andersson 2022-04-22 114 kfree(sw);
71793b579ba682 Bjorn Andersson 2022-04-22 115
71793b579ba682 Bjorn Andersson 2022-04-22 116 return ERR_PTR(err);
bdecb33af34f79 Heikki Krogerus 2018-03-20 117 }
d1c6a769cdf466 Heikki Krogerus 2020-03-02 118 EXPORT_SYMBOL_GPL(fwnode_typec_switch_get);
bdecb33af34f79 Heikki Krogerus 2018-03-20 119

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (7.86 kB)
config (246.71 kB)
Download all attachments

2022-09-27 17:39:40

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] device property: Constify fwnode connection match APIs

On Wed, Sep 28, 2022 at 12:35:10AM +0800, kernel test robot wrote:
> Hi Andy,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on driver-core/driver-core-testing]
> [cannot apply to usb/usb-testing westeri-thunderbolt/next linus/master v6.0-rc7 next-20220923]
> [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/device-property-Keep-dev_fwnode-and-dev_fwnode_const-separate/20220927-223109
> base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 1da40c2667388dd70306bfd3d4dcb49fd20b50a9
> config: sh-allmodconfig
> compiler: sh4-linux-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # https://github.com/intel-lab-lkp/linux/commit/34401a778cc4e8ddd9610bf7f76d8b7e4fff142e
> git remote add linux-review https://github.com/intel-lab-lkp/linux
> git fetch --no-tags linux-review Andy-Shevchenko/device-property-Keep-dev_fwnode-and-dev_fwnode_const-separate/20220927-223109
> git checkout 34401a778cc4e8ddd9610bf7f76d8b7e4fff142e
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash drivers/usb/typec/
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
>
> All errors (new ones prefixed by >>):

Thanks, fixed locally for v2.

--
With Best Regards,
Andy Shevchenko


2022-09-27 20:18:34

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] device property: Constify fwnode connection match APIs

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on driver-core/driver-core-testing]
[cannot apply to usb/usb-testing westeri-thunderbolt/next linus/master v6.0-rc7 next-20220923]
[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/device-property-Keep-dev_fwnode-and-dev_fwnode_const-separate/20220927-223109
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 1da40c2667388dd70306bfd3d4dcb49fd20b50a9
config: hexagon-randconfig-r045-20220927
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/34401a778cc4e8ddd9610bf7f76d8b7e4fff142e
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Andy-Shevchenko/device-property-Keep-dev_fwnode-and-dev_fwnode_const-separate/20220927-223109
git checkout 34401a778cc4e8ddd9610bf7f76d8b7e4fff142e
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/usb/typec/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> drivers/usb/typec/mux.c:84:13: error: incompatible function pointer types passing 'void *(struct fwnode_handle *, const char *, void *)' to parameter of type 'devcon_match_fn_t' (aka 'void *(*)(const struct fwnode_handle *, const char *, void *)') [-Wincompatible-function-pointer-types]
typec_switch_match,
^~~~~~~~~~~~~~~~~~
include/linux/property.h:457:26: note: passing argument to parameter 'match' here
devcon_match_fn_t match,
^
drivers/usb/typec/mux.c:352:27: error: incompatible function pointer types passing 'void *(struct fwnode_handle *, const char *, void *)' to parameter of type 'devcon_match_fn_t' (aka 'void *(*)(const struct fwnode_handle *, const char *, void *)') [-Wincompatible-function-pointer-types]
(void *)desc, typec_mux_match,
^~~~~~~~~~~~~~~
include/linux/property.h:457:26: note: passing argument to parameter 'match' here
devcon_match_fn_t match,
^
2 errors generated.


vim +84 drivers/usb/typec/mux.c

bdecb33af34f79 Heikki Krogerus 2018-03-20 61
bdecb33af34f79 Heikki Krogerus 2018-03-20 62 /**
d1c6a769cdf466 Heikki Krogerus 2020-03-02 63 * fwnode_typec_switch_get - Find USB Type-C orientation switch
d1c6a769cdf466 Heikki Krogerus 2020-03-02 64 * @fwnode: The caller device node
bdecb33af34f79 Heikki Krogerus 2018-03-20 65 *
bdecb33af34f79 Heikki Krogerus 2018-03-20 66 * Finds a switch linked with @dev. Returns a reference to the switch on
bdecb33af34f79 Heikki Krogerus 2018-03-20 67 * success, NULL if no matching connection was found, or
bdecb33af34f79 Heikki Krogerus 2018-03-20 68 * ERR_PTR(-EPROBE_DEFER) when a connection was found but the switch
bdecb33af34f79 Heikki Krogerus 2018-03-20 69 * has not been enumerated yet.
bdecb33af34f79 Heikki Krogerus 2018-03-20 70 */
d1c6a769cdf466 Heikki Krogerus 2020-03-02 71 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
bdecb33af34f79 Heikki Krogerus 2018-03-20 72 {
71793b579ba682 Bjorn Andersson 2022-04-22 73 struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
bdecb33af34f79 Heikki Krogerus 2018-03-20 74 struct typec_switch *sw;
71793b579ba682 Bjorn Andersson 2022-04-22 75 int count;
71793b579ba682 Bjorn Andersson 2022-04-22 76 int err;
71793b579ba682 Bjorn Andersson 2022-04-22 77 int i;
bdecb33af34f79 Heikki Krogerus 2018-03-20 78
713fd49b430c37 Bjorn Andersson 2022-04-22 79 sw = kzalloc(sizeof(*sw), GFP_KERNEL);
713fd49b430c37 Bjorn Andersson 2022-04-22 80 if (!sw)
713fd49b430c37 Bjorn Andersson 2022-04-22 81 return ERR_PTR(-ENOMEM);
713fd49b430c37 Bjorn Andersson 2022-04-22 82
71793b579ba682 Bjorn Andersson 2022-04-22 83 count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
71793b579ba682 Bjorn Andersson 2022-04-22 @84 typec_switch_match,
71793b579ba682 Bjorn Andersson 2022-04-22 85 (void **)sw_devs,
71793b579ba682 Bjorn Andersson 2022-04-22 86 ARRAY_SIZE(sw_devs));
71793b579ba682 Bjorn Andersson 2022-04-22 87 if (count <= 0) {
713fd49b430c37 Bjorn Andersson 2022-04-22 88 kfree(sw);
71793b579ba682 Bjorn Andersson 2022-04-22 89 return NULL;
713fd49b430c37 Bjorn Andersson 2022-04-22 90 }
713fd49b430c37 Bjorn Andersson 2022-04-22 91
71793b579ba682 Bjorn Andersson 2022-04-22 92 for (i = 0; i < count; i++) {
71793b579ba682 Bjorn Andersson 2022-04-22 93 if (IS_ERR(sw_devs[i])) {
71793b579ba682 Bjorn Andersson 2022-04-22 94 err = PTR_ERR(sw_devs[i]);
71793b579ba682 Bjorn Andersson 2022-04-22 95 goto put_sw_devs;
71793b579ba682 Bjorn Andersson 2022-04-22 96 }
71793b579ba682 Bjorn Andersson 2022-04-22 97 }
713fd49b430c37 Bjorn Andersson 2022-04-22 98
71793b579ba682 Bjorn Andersson 2022-04-22 99 for (i = 0; i < count; i++) {
71793b579ba682 Bjorn Andersson 2022-04-22 100 WARN_ON(!try_module_get(sw_devs[i]->dev.parent->driver->owner));
71793b579ba682 Bjorn Andersson 2022-04-22 101 sw->sw_devs[i] = sw_devs[i];
71793b579ba682 Bjorn Andersson 2022-04-22 102 }
71793b579ba682 Bjorn Andersson 2022-04-22 103
71793b579ba682 Bjorn Andersson 2022-04-22 104 sw->num_sw_devs = count;
bdecb33af34f79 Heikki Krogerus 2018-03-20 105
bdecb33af34f79 Heikki Krogerus 2018-03-20 106 return sw;
71793b579ba682 Bjorn Andersson 2022-04-22 107
71793b579ba682 Bjorn Andersson 2022-04-22 108 put_sw_devs:
71793b579ba682 Bjorn Andersson 2022-04-22 109 for (i = 0; i < count; i++) {
71793b579ba682 Bjorn Andersson 2022-04-22 110 if (!IS_ERR(sw_devs[i]))
71793b579ba682 Bjorn Andersson 2022-04-22 111 put_device(&sw_devs[i]->dev);
71793b579ba682 Bjorn Andersson 2022-04-22 112 }
71793b579ba682 Bjorn Andersson 2022-04-22 113
71793b579ba682 Bjorn Andersson 2022-04-22 114 kfree(sw);
71793b579ba682 Bjorn Andersson 2022-04-22 115
71793b579ba682 Bjorn Andersson 2022-04-22 116 return ERR_PTR(err);
bdecb33af34f79 Heikki Krogerus 2018-03-20 117 }
d1c6a769cdf466 Heikki Krogerus 2020-03-02 118 EXPORT_SYMBOL_GPL(fwnode_typec_switch_get);
bdecb33af34f79 Heikki Krogerus 2018-03-20 119

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (7.24 kB)
config (151.63 kB)
Download all attachments

2022-09-27 21:16:17

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v1 1/5] device property: Keep dev_fwnode() and dev_fwnode_const() separate

Hi Andy,

Thanks for the set.

On Tue, Sep 27, 2022 at 05:28:17PM +0300, Andy Shevchenko wrote:
> It's not fully correct to take a const parameter pointer to a struct
> and return a non-const pointer to a member of that struct.

I guess you could go as far as saying it's not at all correct. :-)

>
> Instead, introduce a const version of the dev_fwnode() API which takes
> and returns const pointers and use it where it's applicable.
>
> Suggested-by: Sakari Ailus <[email protected]>
> Fixes: aade55c86033 ("device property: Add const qualifier to device_get_match_data() parameter")
> Signed-off-by: Andy Shevchenko <[email protected]>

For the set:

Reviewed-by: Sakari Ailus <[email protected]>

--
Kind regards,

Sakari Ailus

2022-09-28 08:17:51

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v1 1/5] device property: Keep dev_fwnode() and dev_fwnode_const() separate

On Tue, Sep 27, 2022 at 05:28:17PM +0300, Andy Shevchenko wrote:
> It's not fully correct to take a const parameter pointer to a struct
> and return a non-const pointer to a member of that struct.
>
> Instead, introduce a const version of the dev_fwnode() API which takes
> and returns const pointers and use it where it's applicable.
>
> Suggested-by: Sakari Ailus <[email protected]>
> Fixes: aade55c86033 ("device property: Add const qualifier to device_get_match_data() parameter")
> Signed-off-by: Andy Shevchenko <[email protected]>

For the whole series:

Acked-by: Heikki Krogerus <[email protected]>

> ---
> drivers/base/property.c | 11 +++++++++--
> include/linux/property.h | 3 ++-
> 2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 4d6278a84868..699f1b115e0a 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -17,13 +17,20 @@
> #include <linux/property.h>
> #include <linux/phy.h>
>
> -struct fwnode_handle *dev_fwnode(const struct device *dev)
> +struct fwnode_handle *dev_fwnode(struct device *dev)
> {
> return IS_ENABLED(CONFIG_OF) && dev->of_node ?
> of_fwnode_handle(dev->of_node) : dev->fwnode;
> }
> EXPORT_SYMBOL_GPL(dev_fwnode);
>
> +const struct fwnode_handle *dev_fwnode_const(const struct device *dev)
> +{
> + return IS_ENABLED(CONFIG_OF) && dev->of_node ?
> + of_fwnode_handle(dev->of_node) : dev->fwnode;
> +}
> +EXPORT_SYMBOL_GPL(dev_fwnode_const);
> +
> /**
> * device_property_present - check if a property of a device is present
> * @dev: Device whose property is being checked
> @@ -1202,7 +1209,7 @@ EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
>
> const void *device_get_match_data(const struct device *dev)
> {
> - return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
> + return fwnode_call_ptr_op(dev_fwnode_const(dev), device_get_match_data, dev);
> }
> EXPORT_SYMBOL_GPL(device_get_match_data);
>
> diff --git a/include/linux/property.h b/include/linux/property.h
> index 117cc200c656..ae5d7f8eccf4 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -32,7 +32,8 @@ enum dev_dma_attr {
> DEV_DMA_COHERENT,
> };
>
> -struct fwnode_handle *dev_fwnode(const struct device *dev);
> +struct fwnode_handle *dev_fwnode(struct device *dev);
> +const struct fwnode_handle *dev_fwnode_const(const struct device *dev);
>
> bool device_property_present(struct device *dev, const char *propname);
> int device_property_read_u8_array(struct device *dev, const char *propname,
> --
> 2.35.1

--
heikki

2022-09-28 13:00:03

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v1 1/5] device property: Keep dev_fwnode() and dev_fwnode_const() separate

On Wed, Sep 28, 2022 at 9:36 AM Heikki Krogerus
<[email protected]> wrote:
>
> On Tue, Sep 27, 2022 at 05:28:17PM +0300, Andy Shevchenko wrote:
> > It's not fully correct to take a const parameter pointer to a struct
> > and return a non-const pointer to a member of that struct.
> >
> > Instead, introduce a const version of the dev_fwnode() API which takes
> > and returns const pointers and use it where it's applicable.
> >
> > Suggested-by: Sakari Ailus <[email protected]>
> > Fixes: aade55c86033 ("device property: Add const qualifier to device_get_match_data() parameter")
> > Signed-off-by: Andy Shevchenko <[email protected]>
>
> For the whole series:
>
> Acked-by: Heikki Krogerus <[email protected]>
>
> > ---
> > drivers/base/property.c | 11 +++++++++--
> > include/linux/property.h | 3 ++-
> > 2 files changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/base/property.c b/drivers/base/property.c
> > index 4d6278a84868..699f1b115e0a 100644
> > --- a/drivers/base/property.c
> > +++ b/drivers/base/property.c
> > @@ -17,13 +17,20 @@
> > #include <linux/property.h>
> > #include <linux/phy.h>
> >
> > -struct fwnode_handle *dev_fwnode(const struct device *dev)
> > +struct fwnode_handle *dev_fwnode(struct device *dev)
> > {
> > return IS_ENABLED(CONFIG_OF) && dev->of_node ?
> > of_fwnode_handle(dev->of_node) : dev->fwnode;
> > }
> > EXPORT_SYMBOL_GPL(dev_fwnode);
> >
> > +const struct fwnode_handle *dev_fwnode_const(const struct device *dev)
> > +{
> > + return IS_ENABLED(CONFIG_OF) && dev->of_node ?
> > + of_fwnode_handle(dev->of_node) : dev->fwnode;
> > +}
> > +EXPORT_SYMBOL_GPL(dev_fwnode_const);
> > +
> > /**
> > * device_property_present - check if a property of a device is present
> > * @dev: Device whose property is being checked
> > @@ -1202,7 +1209,7 @@ EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
> >
> > const void *device_get_match_data(const struct device *dev)
> > {
> > - return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
> > + return fwnode_call_ptr_op(dev_fwnode_const(dev), device_get_match_data, dev);
> > }
> > EXPORT_SYMBOL_GPL(device_get_match_data);
> >
> > diff --git a/include/linux/property.h b/include/linux/property.h
> > index 117cc200c656..ae5d7f8eccf4 100644
> > --- a/include/linux/property.h
> > +++ b/include/linux/property.h
> > @@ -32,7 +32,8 @@ enum dev_dma_attr {
> > DEV_DMA_COHERENT,
> > };
> >
> > -struct fwnode_handle *dev_fwnode(const struct device *dev);
> > +struct fwnode_handle *dev_fwnode(struct device *dev);
> > +const struct fwnode_handle *dev_fwnode_const(const struct device *dev);
> >
> > bool device_property_present(struct device *dev, const char *propname);
> > int device_property_read_u8_array(struct device *dev, const char *propname,
> > --

So I would like all of you to see the response from Greg to the v2 of
this patch and provide your input in that thread:

https://lore.kernel.org/linux-acpi/[email protected]/T/#u