diff mbox series

[RFC,03/10] base: swnode: use fwnode_get_match_data()

Message ID 20220221162652.103834-4-clement.leger@bootlin.com (mailing list archive)
State RFC
Headers show
Series add support for fwnode in i2c mux system and sfp | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Clément Léger Feb. 21, 2022, 4:26 p.m. UTC
In order to allow matching devices with software node with
device_get_match_data(), use fwnode_get_match_data() for
.device_get_match_data operation.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 drivers/base/swnode.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko Feb. 21, 2022, 5:48 p.m. UTC | #1
On Mon, Feb 21, 2022 at 05:26:45PM +0100, Clément Léger wrote:
> In order to allow matching devices with software node with
> device_get_match_data(), use fwnode_get_match_data() for
> .device_get_match_data operation.

...

> +	.device_get_match_data = fwnode_get_match_data,

Huh? It should be other way around, no?
I mean that each of the resource providers may (or may not) provide a method
for the specific fwnode abstraction.
Clément Léger Feb. 22, 2022, 8:39 a.m. UTC | #2
Le Mon, 21 Feb 2022 19:48:00 +0200,
Andy Shevchenko <andriy.shevchenko@linux.intel.com> a écrit :

> On Mon, Feb 21, 2022 at 05:26:45PM +0100, Clément Léger wrote:
> > In order to allow matching devices with software node with
> > device_get_match_data(), use fwnode_get_match_data() for
> > .device_get_match_data operation.  
> 
> ...
> 
> > +	.device_get_match_data = fwnode_get_match_data,  
> 
> Huh? It should be other way around, no?
> I mean that each of the resource providers may (or may not) provide a
> method for the specific fwnode abstraction.
> 

Indeed, it should be the other way. But since this function is generic
and uses only fwnode API I guessed it would be more convenient to
define it in the fwnode generic part and use it for specific
implementation. I could have modified device_get_match_data to call it
if there was no .device_get_match_data operation like this:

const void *device_get_match_data(struct device *dev)
{
	if (!fwnode_has_op(fwnode, device_get_match_data)
		return fwnode_get_match_data(dev);
	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
}

But I thought it was more convenient to do it by setting the
.device_get_match_data field of software_node operations.
Sakari Ailus Feb. 23, 2022, 3:05 p.m. UTC | #3
Hi Clément,

On Tue, Feb 22, 2022 at 09:39:21AM +0100, Clément Léger wrote:
> Le Mon, 21 Feb 2022 19:48:00 +0200,
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> a écrit :
> 
> > On Mon, Feb 21, 2022 at 05:26:45PM +0100, Clément Léger wrote:
> > > In order to allow matching devices with software node with
> > > device_get_match_data(), use fwnode_get_match_data() for
> > > .device_get_match_data operation.  
> > 
> > ...
> > 
> > > +	.device_get_match_data = fwnode_get_match_data,  
> > 
> > Huh? It should be other way around, no?
> > I mean that each of the resource providers may (or may not) provide a
> > method for the specific fwnode abstraction.
> > 
> 
> Indeed, it should be the other way. But since this function is generic
> and uses only fwnode API I guessed it would be more convenient to
> define it in the fwnode generic part and use it for specific
> implementation. I could have modified device_get_match_data to call it
> if there was no .device_get_match_data operation like this:
> 
> const void *device_get_match_data(struct device *dev)
> {
> 	if (!fwnode_has_op(fwnode, device_get_match_data)
> 		return fwnode_get_match_data(dev);
> 	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
> }
> 
> But I thought it was more convenient to do it by setting the
> .device_get_match_data field of software_node operations.

Should this function be called e.g. software_node_get_match_data() instead,
as it seems to be specific to software nodes?
Clément Léger Feb. 23, 2022, 3:15 p.m. UTC | #4
Le Wed, 23 Feb 2022 17:05:22 +0200,
Sakari Ailus <sakari.ailus@linux.intel.com> a écrit :

> > const void *device_get_match_data(struct device *dev)
> > {
> > 	if (!fwnode_has_op(fwnode, device_get_match_data)
> > 		return fwnode_get_match_data(dev);
> > 	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
> > }
> > 
> > But I thought it was more convenient to do it by setting the
> > .device_get_match_data field of software_node operations.  
> 
> Should this function be called e.g. software_node_get_match_data() instead,
> as it seems to be specific to software nodes?

Hi Sakari,

You are right, since the only user of this function currently is the
software_node operations, then I should rename it and move it to
swnode.c maybe.
Sakari Ailus Feb. 23, 2022, 3:21 p.m. UTC | #5
On Wed, Feb 23, 2022 at 04:15:35PM +0100, Clément Léger wrote:
> Le Wed, 23 Feb 2022 17:05:22 +0200,
> Sakari Ailus <sakari.ailus@linux.intel.com> a écrit :
> 
> > > const void *device_get_match_data(struct device *dev)
> > > {
> > > 	if (!fwnode_has_op(fwnode, device_get_match_data)
> > > 		return fwnode_get_match_data(dev);
> > > 	return fwnode_call_ptr_op(dev_fwnode(dev),device_get_match_data, dev);
> > > }
> > > 
> > > But I thought it was more convenient to do it by setting the
> > > .device_get_match_data field of software_node operations.  
> > 
> > Should this function be called e.g. software_node_get_match_data() instead,
> > as it seems to be specific to software nodes?
> 
> Hi Sakari,
> 
> You are right, since the only user of this function currently is the
> software_node operations, then I should rename it and move it to
> swnode.c maybe.

It might be also fit to be used in OF, based on how it looks like.

But currently the original naming makes it seem an fwnode property API
function and that is misleading. I'd move this to swnode.c now with a new
software node specific name, and rethink the naming matter if there would
seem to be possibilities for code re-use.
diff mbox series

Patch

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 0a482212c7e8..783ad18f49af 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -662,6 +662,7 @@  software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode,
 static const struct fwnode_operations software_node_ops = {
 	.get = software_node_get,
 	.put = software_node_put,
+	.device_get_match_data = fwnode_get_match_data,
 	.property_present = software_node_property_present,
 	.property_read_int_array = software_node_read_int_array,
 	.property_read_string_array = software_node_read_string_array,