diff mbox series

[wpan-next,v2,3/6] ieee802154: Introduce a helper to validate a channel

Message ID 20221217000226.646767-4-miquel.raynal@bootlin.com (mailing list archive)
State Superseded
Headers show
Series IEEE 802.15.4 passive scan support | expand

Commit Message

Miquel Raynal Dec. 17, 2022, 12:02 a.m. UTC
This helper for now only checks if the page member and channel member
are valid (in the specification range) and supported (by checking the
device capabilities). Soon two new parameters will be introduced and
having this helper will let us only modify its content rather than
modifying the logic everywhere else in the subsystem.

There is not functional change.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 include/net/cfg802154.h   | 11 +++++++++++
 net/ieee802154/nl802154.c |  3 +--
 2 files changed, 12 insertions(+), 2 deletions(-)

Comments

Stefan Schmidt Jan. 3, 2023, 2:14 p.m. UTC | #1
Hello Miquel.

On 17.12.22 01:02, Miquel Raynal wrote:
> This helper for now only checks if the page member and channel member
> are valid (in the specification range) and supported (by checking the
> device capabilities). Soon two new parameters will be introduced and
> having this helper will let us only modify its content rather than
> modifying the logic everywhere else in the subsystem.
> 
> There is not functional change.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>   include/net/cfg802154.h   | 11 +++++++++++
>   net/ieee802154/nl802154.c |  3 +--
>   2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> index 76d4f95e9974..11bedfa96371 100644
> --- a/include/net/cfg802154.h
> +++ b/include/net/cfg802154.h
> @@ -246,6 +246,17 @@ static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
>   	write_pnet(&wpan_phy->_net, net);
>   }
>   
> +static inline bool ieee802154_chan_is_valid(struct wpan_phy *phy,
> +                                            u8 page, u8 channel)
> +{
> +        if (page > IEEE802154_MAX_PAGE ||
> +            channel > IEEE802154_MAX_CHANNEL ||
> +            !(phy->supported.channels[page] & BIT(channel)))
> +                return false;
> +
> +	return true;
> +}
> +

This patch has some indent problems.

Commit 6bbb25ee282b ("ieee802154: Introduce a helper to validate a channel")
----------------------------------------------------------------------------
ERROR: code indent should use tabs where possible
#31: FILE: include/net/cfg802154.h:250:
+                                            u8 page, u8 channel)$

WARNING: please, no spaces at the start of a line
#31: FILE: include/net/cfg802154.h:250:
+                                            u8 page, u8 channel)$

ERROR: code indent should use tabs where possible
#33: FILE: include/net/cfg802154.h:252:
+        if (page > IEEE802154_MAX_PAGE ||$

WARNING: please, no spaces at the start of a line
#33: FILE: include/net/cfg802154.h:252:
+        if (page > IEEE802154_MAX_PAGE ||$

ERROR: code indent should use tabs where possible
#34: FILE: include/net/cfg802154.h:253:
+            channel > IEEE802154_MAX_CHANNEL ||$

WARNING: please, no spaces at the start of a line
#34: FILE: include/net/cfg802154.h:253:
+            channel > IEEE802154_MAX_CHANNEL ||$

ERROR: code indent should use tabs where possible
#35: FILE: include/net/cfg802154.h:254:
+            !(phy->supported.channels[page] & BIT(channel)))$

WARNING: please, no spaces at the start of a line
#35: FILE: include/net/cfg802154.h:254:
+            !(phy->supported.channels[page] & BIT(channel)))$

ERROR: code indent should use tabs where possible
#36: FILE: include/net/cfg802154.h:255:
+                return false;$

WARNING: please, no spaces at the start of a line
#36: FILE: include/net/cfg802154.h:255:
+                return false;$

total: 5 errors, 5 warnings, 0 checks, 26 lines checked

regards
Stefan Schmidt
Miquel Raynal Jan. 3, 2023, 2:59 p.m. UTC | #2
Hi Stefan,

stefan@datenfreihafen.org wrote on Tue, 3 Jan 2023 15:14:46 +0100:

> Hello Miquel.
> 
> On 17.12.22 01:02, Miquel Raynal wrote:
> > This helper for now only checks if the page member and channel member
> > are valid (in the specification range) and supported (by checking the
> > device capabilities). Soon two new parameters will be introduced and
> > having this helper will let us only modify its content rather than
> > modifying the logic everywhere else in the subsystem.
> > 
> > There is not functional change.
> > 
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >   include/net/cfg802154.h   | 11 +++++++++++
> >   net/ieee802154/nl802154.c |  3 +--
> >   2 files changed, 12 insertions(+), 2 deletions(-)
> > 
> > diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> > index 76d4f95e9974..11bedfa96371 100644
> > --- a/include/net/cfg802154.h
> > +++ b/include/net/cfg802154.h
> > @@ -246,6 +246,17 @@ static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
> >   	write_pnet(&wpan_phy->_net, net);
> >   }  
> >   > +static inline bool ieee802154_chan_is_valid(struct wpan_phy *phy,  
> > +                                            u8 page, u8 channel)
> > +{
> > +        if (page > IEEE802154_MAX_PAGE ||
> > +            channel > IEEE802154_MAX_CHANNEL ||
> > +            !(phy->supported.channels[page] & BIT(channel)))
> > +                return false;
> > +
> > +	return true;
> > +}
> > +  
> 
> This patch has some indent problems.

I will check all the patches of this series and fix what checkpatch.pl
reports.

https://media.tenor.com/025m1-otvn0AAAAC/shame-game-of-thrones.gif

Cheers,
Miquèl

> 
> Commit 6bbb25ee282b ("ieee802154: Introduce a helper to validate a channel")
> ----------------------------------------------------------------------------
> ERROR: code indent should use tabs where possible
> #31: FILE: include/net/cfg802154.h:250:
> +                                            u8 page, u8 channel)$
> 
> WARNING: please, no spaces at the start of a line
> #31: FILE: include/net/cfg802154.h:250:
> +                                            u8 page, u8 channel)$
> 
> ERROR: code indent should use tabs where possible
> #33: FILE: include/net/cfg802154.h:252:
> +        if (page > IEEE802154_MAX_PAGE ||$
> 
> WARNING: please, no spaces at the start of a line
> #33: FILE: include/net/cfg802154.h:252:
> +        if (page > IEEE802154_MAX_PAGE ||$
> 
> ERROR: code indent should use tabs where possible
> #34: FILE: include/net/cfg802154.h:253:
> +            channel > IEEE802154_MAX_CHANNEL ||$
> 
> WARNING: please, no spaces at the start of a line
> #34: FILE: include/net/cfg802154.h:253:
> +            channel > IEEE802154_MAX_CHANNEL ||$
> 
> ERROR: code indent should use tabs where possible
> #35: FILE: include/net/cfg802154.h:254:
> +            !(phy->supported.channels[page] & BIT(channel)))$
> 
> WARNING: please, no spaces at the start of a line
> #35: FILE: include/net/cfg802154.h:254:
> +            !(phy->supported.channels[page] & BIT(channel)))$
> 
> ERROR: code indent should use tabs where possible
> #36: FILE: include/net/cfg802154.h:255:
> +                return false;$
> 
> WARNING: please, no spaces at the start of a line
> #36: FILE: include/net/cfg802154.h:255:
> +                return false;$
> 
> total: 5 errors, 5 warnings, 0 checks, 26 lines checked
> 
> regards
> Stefan Schmidt
Miquel Raynal Jan. 3, 2023, 4:58 p.m. UTC | #3
Hi Stefan,

miquel.raynal@bootlin.com wrote on Tue, 3 Jan 2023 15:59:50 +0100:

> Hi Stefan,
> 
> stefan@datenfreihafen.org wrote on Tue, 3 Jan 2023 15:14:46 +0100:
> 
> > Hello Miquel.
> > 
> > On 17.12.22 01:02, Miquel Raynal wrote:  
> > > This helper for now only checks if the page member and channel member
> > > are valid (in the specification range) and supported (by checking the
> > > device capabilities). Soon two new parameters will be introduced and
> > > having this helper will let us only modify its content rather than
> > > modifying the logic everywhere else in the subsystem.
> > > 
> > > There is not functional change.
> > > 
> > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > > ---
> > >   include/net/cfg802154.h   | 11 +++++++++++
> > >   net/ieee802154/nl802154.c |  3 +--
> > >   2 files changed, 12 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> > > index 76d4f95e9974..11bedfa96371 100644
> > > --- a/include/net/cfg802154.h
> > > +++ b/include/net/cfg802154.h
> > > @@ -246,6 +246,17 @@ static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
> > >   	write_pnet(&wpan_phy->_net, net);
> > >   }    
> > >   > +static inline bool ieee802154_chan_is_valid(struct wpan_phy *phy,    
> > > +                                            u8 page, u8 channel)
> > > +{
> > > +        if (page > IEEE802154_MAX_PAGE ||
> > > +            channel > IEEE802154_MAX_CHANNEL ||
> > > +            !(phy->supported.channels[page] & BIT(channel)))
> > > +                return false;
> > > +
> > > +	return true;
> > > +}
> > > +    
> > 
> > This patch has some indent problems.  
> 
> I will check all the patches of this series and fix what checkpatch.pl
> reports.

I left the warnings in the trace.h headers to keep the visual
consistent. The other warnings should be gone.

Thanks,
Miquèl
diff mbox series

Patch

diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 76d4f95e9974..11bedfa96371 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -246,6 +246,17 @@  static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
 	write_pnet(&wpan_phy->_net, net);
 }
 
+static inline bool ieee802154_chan_is_valid(struct wpan_phy *phy,
+                                            u8 page, u8 channel)
+{
+        if (page > IEEE802154_MAX_PAGE ||
+            channel > IEEE802154_MAX_CHANNEL ||
+            !(phy->supported.channels[page] & BIT(channel)))
+                return false;
+
+	return true;
+}
+
 /**
  * struct ieee802154_addr - IEEE802.15.4 device address
  * @mode: Address mode from frame header. Can be one of:
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 64c6c33b28a9..1d703251f74a 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -976,8 +976,7 @@  static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
 	channel = nla_get_u8(info->attrs[NL802154_ATTR_CHANNEL]);
 
 	/* check 802.15.4 constraints */
-	if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL ||
-	    !(rdev->wpan_phy.supported.channels[page] & BIT(channel)))
+	if (!ieee802154_chan_is_valid(&rdev->wpan_phy, page, channel))
 		return -EINVAL;
 
 	return rdev_set_channel(rdev, page, channel);