diff mbox series

net: sysfs: Fix weird usage of class's namespace relevant fields

Message ID 20240905-fix_class_ns-v1-1-88ecccc3517c@quicinc.com (mailing list archive)
State Accepted
Commit 8f088541991bc1716a5ed570456d218241303851
Delegated to: Netdev Maintainers
Headers show
Series net: sysfs: Fix weird usage of class's namespace relevant fields | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
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: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-07--06-00 (tests: 722)

Commit Message

Zijun Hu Sept. 4, 2024, 11:35 p.m. UTC
From: Zijun Hu <quic_zijuhu@quicinc.com>

Device class has two namespace relevant fields which are associated by
the following usage:

struct class {
	...
	const struct kobj_ns_type_operations *ns_type;
	const void *(*namespace)(const struct device *dev);
	...
}
if (dev->class && dev->class->ns_type)
	dev->class->namespace(dev);

The usage looks weird since it checks @ns_type but calls namespace()
it is found for all existing class definitions that the other filed is
also assigned once one is assigned in current kernel tree, so fix this
weird usage by checking @namespace to call namespace().

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
driver-core tree has similar fix as shown below:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=driver-core-next&id=a169a663bfa8198f33a5c1002634cc89e5128025
---
 net/core/net-sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


---
base-commit: 88fac17500f4ea49c7bac136cf1b27e7b9980075
change-id: 20240904-fix_class_ns-adf1ac05b6fc

Best regards,

Comments

Simon Horman Sept. 6, 2024, 10:21 a.m. UTC | #1
On Thu, Sep 05, 2024 at 07:35:38AM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Device class has two namespace relevant fields which are associated by
> the following usage:
> 
> struct class {
> 	...
> 	const struct kobj_ns_type_operations *ns_type;
> 	const void *(*namespace)(const struct device *dev);
> 	...
> }
> if (dev->class && dev->class->ns_type)
> 	dev->class->namespace(dev);
> 
> The usage looks weird since it checks @ns_type but calls namespace()
> it is found for all existing class definitions that the other filed is
> also assigned once one is assigned in current kernel tree, so fix this
> weird usage by checking @namespace to call namespace().
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
> driver-core tree has similar fix as shown below:
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=driver-core-next&id=a169a663bfa8198f33a5c1002634cc89e5128025

Thanks,

I agree that this change is consistent with the one at the link above.
And that, given your explanation there and here, this change
makes sense.

Reviewed-by: Simon Horman <horms@kernel.org>

I don't think there is a need to repost because of this, but for future
reference, please keep in mind that patches like this - non bug fixes for
Networking code - should, in general, be targeted at net-next.

Subject: [PATCH net-next] ...

See: https://docs.kernel.org/process/maintainer-netdev.html
Zijun Hu Sept. 6, 2024, 11:12 a.m. UTC | #2
On 2024/9/6 18:21, Simon Horman wrote:
> On Thu, Sep 05, 2024 at 07:35:38AM +0800, Zijun Hu wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> Device class has two namespace relevant fields which are associated by
>> the following usage:
>>
>> struct class {
>> 	...
>> 	const struct kobj_ns_type_operations *ns_type;
>> 	const void *(*namespace)(const struct device *dev);
>> 	...
>> }
>> if (dev->class && dev->class->ns_type)
>> 	dev->class->namespace(dev);
>>
>> The usage looks weird since it checks @ns_type but calls namespace()
>> it is found for all existing class definitions that the other filed is
>> also assigned once one is assigned in current kernel tree, so fix this
>> weird usage by checking @namespace to call namespace().
>>
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
>> ---
>> driver-core tree has similar fix as shown below:
>> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=driver-core-next&id=a169a663bfa8198f33a5c1002634cc89e5128025
> 
> Thanks,
> 
> I agree that this change is consistent with the one at the link above.
> And that, given your explanation there and here, this change
> makes sense.
> 
> Reviewed-by: Simon Horman <horms@kernel.org>
> 
> I don't think there is a need to repost because of this, but for future
> reference, please keep in mind that patches like this - non bug fixes for
> Networking code - should, in general, be targeted at net-next.
> 
> Subject: [PATCH net-next] ...
> 
> See: https://docs.kernel.org/process/maintainer-netdev.html

thank you very much for such important reminder
i will follow this guidance for further net patches. (^^)
patchwork-bot+netdevbpf@kernel.org Sept. 9, 2024, 9:40 a.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 05 Sep 2024 07:35:38 +0800 you wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Device class has two namespace relevant fields which are associated by
> the following usage:
> 
> struct class {
> 	...
> 	const struct kobj_ns_type_operations *ns_type;
> 	const void *(*namespace)(const struct device *dev);
> 	...
> }
> if (dev->class && dev->class->ns_type)
> 	dev->class->namespace(dev);
> 
> [...]

Here is the summary with links:
  - net: sysfs: Fix weird usage of class's namespace relevant fields
    https://git.kernel.org/netdev/net-next/c/8f088541991b

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 444f23e74f8e..d10c88f569b0 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1056,7 +1056,7 @@  static const void *rx_queue_namespace(const struct kobject *kobj)
 	struct device *dev = &queue->dev->dev;
 	const void *ns = NULL;
 
-	if (dev->class && dev->class->ns_type)
+	if (dev->class && dev->class->namespace)
 		ns = dev->class->namespace(dev);
 
 	return ns;
@@ -1740,7 +1740,7 @@  static const void *netdev_queue_namespace(const struct kobject *kobj)
 	struct device *dev = &queue->dev->dev;
 	const void *ns = NULL;
 
-	if (dev->class && dev->class->ns_type)
+	if (dev->class && dev->class->namespace)
 		ns = dev->class->namespace(dev);
 
 	return ns;