diff mbox series

[V2,net-next,11/11] net: add is_valid_ether_addr check in dev_set_mac_address

Message ID 20240820140154.137876-12-shaojijie@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Add support of HIBMCGE Ethernet Driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 21 this patch: 21
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 79 this patch: 79
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-08-20--21-00 (tests: 692)

Commit Message

Jijie Shao Aug. 20, 2024, 2:01 p.m. UTC
core need test the mac_addr not every driver need to do.

Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jakub Kicinski Aug. 21, 2024, 1:55 a.m. UTC | #1
On Tue, 20 Aug 2024 22:01:54 +0800 Jijie Shao wrote:
> core need test the mac_addr not every driver need to do.
> 
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
>  net/core/dev.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index e7260889d4cb..2e19712184bc 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -9087,6 +9087,8 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
>  		return -EOPNOTSUPP;
>  	if (sa->sa_family != dev->type)
>  		return -EINVAL;
> +	if (!is_valid_ether_addr(sa->sa_data))
> +		return -EADDRNOTAVAIL;

not every netdev is for an Ethernet device
Jijie Shao Aug. 21, 2024, 6:04 a.m. UTC | #2
on 2024/8/21 9:55, Jakub Kicinski wrote:
> On Tue, 20 Aug 2024 22:01:54 +0800 Jijie Shao wrote:
>> core need test the mac_addr not every driver need to do.
>>
>> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
>> ---
>>   net/core/dev.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index e7260889d4cb..2e19712184bc 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -9087,6 +9087,8 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
>>   		return -EOPNOTSUPP;
>>   	if (sa->sa_family != dev->type)
>>   		return -EINVAL;
>> +	if (!is_valid_ether_addr(sa->sa_data))
>> +		return -EADDRNOTAVAIL;
> not every netdev is for an Ethernet device

ok, this patch will be removed in v3.
and the check will move to hibmcge driver.
Thanks a lot.
	
	Jijie Shao
Andrew Lunn Aug. 21, 2024, 12:15 p.m. UTC | #3
On Wed, Aug 21, 2024 at 02:04:01PM +0800, Jijie Shao wrote:
> 
> on 2024/8/21 9:55, Jakub Kicinski wrote:
> > On Tue, 20 Aug 2024 22:01:54 +0800 Jijie Shao wrote:
> > > core need test the mac_addr not every driver need to do.
> > > 
> > > Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> > > ---
> > >   net/core/dev.c | 2 ++
> > >   1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/net/core/dev.c b/net/core/dev.c
> > > index e7260889d4cb..2e19712184bc 100644
> > > --- a/net/core/dev.c
> > > +++ b/net/core/dev.c
> > > @@ -9087,6 +9087,8 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
> > >   		return -EOPNOTSUPP;
> > >   	if (sa->sa_family != dev->type)
> > >   		return -EINVAL;
> > > +	if (!is_valid_ether_addr(sa->sa_data))
> > > +		return -EADDRNOTAVAIL;
> > not every netdev is for an Ethernet device
> 
> ok, this patch will be removed in v3.
> and the check will move to hibmcge driver.

No, you just need to use the correct function to perform the check.

__dev_open() does:

        if (ops->ndo_validate_addr)
                ret = ops->ndo_validate_addr(dev);

	Andrew
Jijie Shao Aug. 22, 2024, 7:33 a.m. UTC | #4
on 2024/8/21 20:15, Andrew Lunn wrote:
> On Wed, Aug 21, 2024 at 02:04:01PM +0800, Jijie Shao wrote:
>> on 2024/8/21 9:55, Jakub Kicinski wrote:
>>> On Tue, 20 Aug 2024 22:01:54 +0800 Jijie Shao wrote:
>>>> core need test the mac_addr not every driver need to do.
>>>>
>>>> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
>>>> ---
>>>>    net/core/dev.c | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/net/core/dev.c b/net/core/dev.c
>>>> index e7260889d4cb..2e19712184bc 100644
>>>> --- a/net/core/dev.c
>>>> +++ b/net/core/dev.c
>>>> @@ -9087,6 +9087,8 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
>>>>    		return -EOPNOTSUPP;
>>>>    	if (sa->sa_family != dev->type)
>>>>    		return -EINVAL;
>>>> +	if (!is_valid_ether_addr(sa->sa_data))
>>>> +		return -EADDRNOTAVAIL;
>>> not every netdev is for an Ethernet device
>> ok, this patch will be removed in v3.
>> and the check will move to hibmcge driver.
> No, you just need to use the correct function to perform the check.
>
> __dev_open() does:
>
>          if (ops->ndo_validate_addr)
>                  ret = ops->ndo_validate_addr(dev);
>
> 	Andrew

okay, it looks perfect!
	
	Jijie Shao
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index e7260889d4cb..2e19712184bc 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9087,6 +9087,8 @@  int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
 		return -EOPNOTSUPP;
 	if (sa->sa_family != dev->type)
 		return -EINVAL;
+	if (!is_valid_ether_addr(sa->sa_data))
+		return -EADDRNOTAVAIL;
 	if (!netif_device_present(dev))
 		return -ENODEV;
 	err = dev_pre_changeaddr_notify(dev, sa->sa_data, extack);