diff mbox series

[net-next,v2,6/9] netlink: introduce typedef for filter function

Message ID 20231116164822.427485-7-jiri@resnulli.us (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series devlink: introduce notifications filtering | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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: 6002 this patch: 6002
netdev/cc_maintainers warning 5 maintainers not CCed: anjali.k.kulkarni@oracle.com Liam.Howlett@oracle.com kuniyu@amazon.com shayagr@amazon.com fw@strlen.de
netdev/build_clang success Errors and warnings before: 2365 this patch: 2365
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: 6337 this patch: 6337
netdev/checkpatch warning WARNING: line length of 84 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc fail Errors and warnings before: 0 this patch: 2
netdev/source_inline success Was 0 now: 0

Commit Message

Jiri Pirko Nov. 16, 2023, 4:48 p.m. UTC
From: Jiri Pirko <jiri@nvidia.com>

Make the code using filter function a bit nicer by consolidating the
filter function arguments using typedef.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 drivers/connector/connector.c | 5 ++---
 include/linux/connector.h     | 6 ++----
 include/linux/netlink.h       | 6 ++++--
 net/netlink/af_netlink.c      | 6 ++----
 4 files changed, 10 insertions(+), 13 deletions(-)

Comments

Simon Horman Nov. 19, 2023, 2:58 p.m. UTC | #1
On Thu, Nov 16, 2023 at 05:48:18PM +0100, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> Make the code using filter function a bit nicer by consolidating the
> filter function arguments using typedef.
> 
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
> ---
> v1->v2:
> - new patch
> ---
>  drivers/connector/connector.c | 5 ++---
>  include/linux/connector.h     | 6 ++----
>  include/linux/netlink.h       | 6 ++++--
>  net/netlink/af_netlink.c      | 6 ++----
>  4 files changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
> index 7f7b94f616a6..4028e8eeba82 100644
> --- a/drivers/connector/connector.c
> +++ b/drivers/connector/connector.c
> @@ -59,9 +59,8 @@ static int cn_already_initialized;
>   * both, or if both are zero then the group is looked up and sent there.
>   */
>  int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
> -	gfp_t gfp_mask,
> -	int (*filter)(struct sock *dsk, struct sk_buff *skb, void *data),
> -	void *filter_data)
> +			 gfp_t gfp_mask, netlink_filter_fn filter,
> +			 void *filter_data)
>  {
>  	struct cn_callback_entry *__cbq;
>  	unsigned int size;
> diff --git a/include/linux/connector.h b/include/linux/connector.h
> index cec2d99ae902..cb18d70d623f 100644
> --- a/include/linux/connector.h
> +++ b/include/linux/connector.h
> @@ -98,10 +98,8 @@ void cn_del_callback(const struct cb_id *id);
>   *
>   * If there are no listeners for given group %-ESRCH can be returned.
>   */
> -int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid,
> -			 u32 group, gfp_t gfp_mask,
> -			 int (*filter)(struct sock *dsk, struct sk_buff *skb,
> -				       void *data),
> +int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
> +			 gfp_t gfp_mask, netlink_filter_fn filter,
>  			 void *filter_data);

nit: It might be good to update the kernel doc to account for
     group => group.
     Curiously the kernel doc already documents filter_data rather
     than data.

...
Jiri Pirko Nov. 20, 2023, 7:58 a.m. UTC | #2
Sun, Nov 19, 2023 at 03:58:55PM CET, horms@kernel.org wrote:
>On Thu, Nov 16, 2023 at 05:48:18PM +0100, Jiri Pirko wrote:
>> From: Jiri Pirko <jiri@nvidia.com>
>> 
>> Make the code using filter function a bit nicer by consolidating the
>> filter function arguments using typedef.
>> 
>> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>> ---
>> v1->v2:
>> - new patch
>> ---
>>  drivers/connector/connector.c | 5 ++---
>>  include/linux/connector.h     | 6 ++----
>>  include/linux/netlink.h       | 6 ++++--
>>  net/netlink/af_netlink.c      | 6 ++----
>>  4 files changed, 10 insertions(+), 13 deletions(-)
>> 
>> diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
>> index 7f7b94f616a6..4028e8eeba82 100644
>> --- a/drivers/connector/connector.c
>> +++ b/drivers/connector/connector.c
>> @@ -59,9 +59,8 @@ static int cn_already_initialized;
>>   * both, or if both are zero then the group is looked up and sent there.
>>   */
>>  int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
>> -	gfp_t gfp_mask,
>> -	int (*filter)(struct sock *dsk, struct sk_buff *skb, void *data),
>> -	void *filter_data)
>> +			 gfp_t gfp_mask, netlink_filter_fn filter,
>> +			 void *filter_data)
>>  {
>>  	struct cn_callback_entry *__cbq;
>>  	unsigned int size;
>> diff --git a/include/linux/connector.h b/include/linux/connector.h
>> index cec2d99ae902..cb18d70d623f 100644
>> --- a/include/linux/connector.h
>> +++ b/include/linux/connector.h
>> @@ -98,10 +98,8 @@ void cn_del_callback(const struct cb_id *id);
>>   *
>>   * If there are no listeners for given group %-ESRCH can be returned.
>>   */
>> -int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid,
>> -			 u32 group, gfp_t gfp_mask,
>> -			 int (*filter)(struct sock *dsk, struct sk_buff *skb,
>> -				       void *data),
>> +int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
>> +			 gfp_t gfp_mask, netlink_filter_fn filter,
>>  			 void *filter_data);
>
>nit: It might be good to update the kernel doc to account for
>     group => group.
>     Curiously the kernel doc already documents filter_data rather
>     than data.

Ah, I copied this from .c file. There is an inconsistency in the
existing code. Will keep the inconsistency.


>
>...
diff mbox series

Patch

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 7f7b94f616a6..4028e8eeba82 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -59,9 +59,8 @@  static int cn_already_initialized;
  * both, or if both are zero then the group is looked up and sent there.
  */
 int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
-	gfp_t gfp_mask,
-	int (*filter)(struct sock *dsk, struct sk_buff *skb, void *data),
-	void *filter_data)
+			 gfp_t gfp_mask, netlink_filter_fn filter,
+			 void *filter_data)
 {
 	struct cn_callback_entry *__cbq;
 	unsigned int size;
diff --git a/include/linux/connector.h b/include/linux/connector.h
index cec2d99ae902..cb18d70d623f 100644
--- a/include/linux/connector.h
+++ b/include/linux/connector.h
@@ -98,10 +98,8 @@  void cn_del_callback(const struct cb_id *id);
  *
  * If there are no listeners for given group %-ESRCH can be returned.
  */
-int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid,
-			 u32 group, gfp_t gfp_mask,
-			 int (*filter)(struct sock *dsk, struct sk_buff *skb,
-				       void *data),
+int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
+			 gfp_t gfp_mask, netlink_filter_fn filter,
 			 void *filter_data);
 
 /**
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 75d7de34c908..d30f599a4c6b 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -228,10 +228,12 @@  bool netlink_strict_get_check(struct sk_buff *skb);
 int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 portid, int nonblock);
 int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 portid,
 		      __u32 group, gfp_t allocation);
+
+typedef int (*netlink_filter_fn)(struct sock *dsk, struct sk_buff *skb, void *data);
+
 int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb,
 			       __u32 portid, __u32 group, gfp_t allocation,
-			       int (*filter)(struct sock *dsk,
-					     struct sk_buff *skb, void *data),
+			       netlink_filter_fn filter,
 			       void *filter_data);
 int netlink_set_err(struct sock *ssk, __u32 portid, __u32 group, int code);
 int netlink_register_notifier(struct notifier_block *nb);
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index eb086b06d60d..6bad718c2966 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1518,10 +1518,8 @@  static void do_one_broadcast(struct sock *sk,
 }
 
 int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb,
-			       u32 portid,
-			       u32 group, gfp_t allocation,
-			       int (*filter)(struct sock *dsk,
-					     struct sk_buff *skb, void *data),
+			       __u32 portid, __u32 group, gfp_t allocation,
+			       netlink_filter_fn filter,
 			       void *filter_data)
 {
 	struct net *net = sock_net(ssk);