diff mbox series

[2/2] device property: add description of fwnode cases

Message ID 20210105091146.25422-3-yung-chuan.liao@linux.intel.com
State Accepted
Commit 3f7bddaf5d5a83aa2eb1e6d72db221d3ec43c813
Headers show
Series Revert "device property: Keep secondary firmware node secondary by type" | expand

Commit Message

Liao, Bard Jan. 5, 2021, 9:11 a.m. UTC
There are only four valid fwnode cases which are
- primary --> secondary --> -ENODEV
- primary --> NULL
- secondary --> -ENODEV
- NULL

dev->fwnode should be converted between the 4 cases above no matter
how/when set_primary_fwnode() and set_secondary_fwnode() are called.
Describe it in the code so people will keep it in mind.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
---
 drivers/base/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Heikki Krogerus Jan. 7, 2021, 2:11 p.m. UTC | #1
On Tue, Jan 05, 2021 at 05:11:46PM +0800, Bard Liao wrote:
> There are only four valid fwnode cases which are

> - primary --> secondary --> -ENODEV

> - primary --> NULL

> - secondary --> -ENODEV

> - NULL

> 

> dev->fwnode should be converted between the 4 cases above no matter

> how/when set_primary_fwnode() and set_secondary_fwnode() are called.

> Describe it in the code so people will keep it in mind.

> 

> Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>


Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>


> ---

>  drivers/base/core.c | 7 +++++++

>  1 file changed, 7 insertions(+)

> 

> diff --git a/drivers/base/core.c b/drivers/base/core.c

> index 51b9545a050b..17eb14607074 100644

> --- a/drivers/base/core.c

> +++ b/drivers/base/core.c

> @@ -4414,6 +4414,12 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)

>   *

>   * Set the device's firmware node pointer to @fwnode, but if a secondary

>   * firmware node of the device is present, preserve it.

> + *

> + * Valid fwnode cases are:

> + *  - primary --> secondary --> -ENODEV

> + *  - primary --> NULL

> + *  - secondary --> -ENODEV

> + *  - NULL

>   */

>  void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

>  {

> @@ -4432,6 +4438,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

>  	} else {

>  		if (fwnode_is_primary(fn)) {

>  			dev->fwnode = fn->secondary;

> +			/* Set fn->secondary = NULL to keep fn as a primary fwnode */

>  			if (!(parent && fn == parent->fwnode))

>  				fn->secondary = NULL;

>  		} else {

> -- 

> 2.17.1


thanks,

-- 
heikki
Rafael J. Wysocki Jan. 7, 2021, 4:58 p.m. UTC | #2
On Thu, Jan 7, 2021 at 3:11 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>

> On Tue, Jan 05, 2021 at 05:11:46PM +0800, Bard Liao wrote:

> > There are only four valid fwnode cases which are

> > - primary --> secondary --> -ENODEV

> > - primary --> NULL

> > - secondary --> -ENODEV

> > - NULL

> >

> > dev->fwnode should be converted between the 4 cases above no matter

> > how/when set_primary_fwnode() and set_secondary_fwnode() are called.

> > Describe it in the code so people will keep it in mind.

> >

> > Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>

>

> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

>

> > ---

> >  drivers/base/core.c | 7 +++++++

> >  1 file changed, 7 insertions(+)

> >

> > diff --git a/drivers/base/core.c b/drivers/base/core.c

> > index 51b9545a050b..17eb14607074 100644

> > --- a/drivers/base/core.c

> > +++ b/drivers/base/core.c

> > @@ -4414,6 +4414,12 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)

> >   *

> >   * Set the device's firmware node pointer to @fwnode, but if a secondary

> >   * firmware node of the device is present, preserve it.

> > + *

> > + * Valid fwnode cases are:

> > + *  - primary --> secondary --> -ENODEV

> > + *  - primary --> NULL

> > + *  - secondary --> -ENODEV

> > + *  - NULL

> >   */

> >  void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

> >  {

> > @@ -4432,6 +4438,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

> >       } else {

> >               if (fwnode_is_primary(fn)) {

> >                       dev->fwnode = fn->secondary;

> > +                     /* Set fn->secondary = NULL to keep fn as a primary fwnode */

> >                       if (!(parent && fn == parent->fwnode))

> >                               fn->secondary = NULL;

> >               } else {

> > --


Applied (with a minor edit in the new comment) along with the [1/2] as
5.11-rc material, thanks!
diff mbox series

Patch

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 51b9545a050b..17eb14607074 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4414,6 +4414,12 @@  static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
  *
  * Set the device's firmware node pointer to @fwnode, but if a secondary
  * firmware node of the device is present, preserve it.
+ *
+ * Valid fwnode cases are:
+ *  - primary --> secondary --> -ENODEV
+ *  - primary --> NULL
+ *  - secondary --> -ENODEV
+ *  - NULL
  */
 void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 {
@@ -4432,6 +4438,7 @@  void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 	} else {
 		if (fwnode_is_primary(fn)) {
 			dev->fwnode = fn->secondary;
+			/* Set fn->secondary = NULL to keep fn as a primary fwnode */
 			if (!(parent && fn == parent->fwnode))
 				fn->secondary = NULL;
 		} else {