Skip to contentSkip to conversation

Remove weird and needless 'return' for void APIs

PATCH Applied Zijun Hu 13 participants 42 messages Feb 21, 2025 – Mar 13, 2025

Subsystems (18)
lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

cover Remove weird and needless 'return' for void APIs

This patch series is to remove weird and needless 'return' for void APIs under include/ with the following pattern:

api_header.h:

void api_func_a(...);

static inline void api_func_b(...)

{
	return api_func_a(...);
}

Remove the needless 'return' in api_func_b().

---
Zijun Hu (18):
mm/mmu_gather: Remove needless return in void API tlb_remove_page()
cpu: Remove needless return in void API suspend_enable_secondary_cpus()
crypto: api - Remove needless return in void API crypto_free_tfm()
crypto: scomp - Remove needless return in void API crypto_scomp_free_ctx()
sysfs: Remove needless return in void API sysfs_enable_ns()
skbuff: Remove needless return in void API consume_skb()
wifi: mac80211: Remove needless return in void API _ieee80211_hw_set()
net: sched: Remove needless return in void API qdisc_watchdog_schedule_ns() ipv4/igmp: Remove needless return in void API ip_mc_dec_group() IB/rdmavt: Remove needless return in void API rvt_mod_retry_timer()
ratelimit: Remove needless return in void API ratelimit_default_init()
siox: Remove needless return in void API siox_driver_unregister()
gpiolib: Remove needless return in two void APIs
PM: wakeup: Remove needless return in three void APIs
mfd: db8500-prcmu: Remove needless return in three void APIs
rhashtable: Remove needless return in three void APIs
dma-mapping: Remove needless return in five void APIs
mtd: nand: Do not return void function in void function

 include/asm-generic/tlb.h           |  2 +-
 include/crypto/internal/scompress.h |  2 +-
 include/linux/cpu.h                 |  2 +-
 include/linux/crypto.h              |  2 +-
 include/linux/dma-mapping.h         | 12 ++++++------
 include/linux/gpio.h                |  4 ++--
 include/linux/igmp.h                |  2 +-
 include/linux/mfd/dbx500-prcmu.h    |  6 +++---
 include/linux/mtd/nand.h            | 18 ++++++++++++------
 include/linux/pm_wakeup.h           |  6 +++---
 include/linux/ratelimit.h           |  4 ++--
 include/linux/rhashtable.h          |  6 +++---
 include/linux/siox.h                |  2 +-
 include/linux/skbuff.h              |  2 +-
 include/linux/sysfs.h               |  2 +-
 include/net/mac80211.h              |  2 +-
 include/net/pkt_sched.h             |  2 +-
 include/rdma/rdmavt_qp.h            |  2 +-
 18 files changed, 42 insertions(+), 36 deletions(-)

---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250221-rmv_return-f1dc82d492f0

Best regards,

Signature · 1 line
Zijun Hu <[email protected]>
author
#1 lore raw

PATCH 1/18 mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Remove needless 'return' in void API tlb_remove_page() since both the API and tlb_remove_page_size() are void functions.

---
 include/asm-generic/tlb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/tlb.h +1 -1
index e402aef79c93..812110813b84 100644
@@ -501,7 +501,7 @@ static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb,
  */
 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }
 
 static inline void tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt)
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 13 lines · Zijun Hu

Remove needless 'return' in void API tlb_remove_page() since both the API and tlb_remove_page_size() are void functions.

---
 include/asm-generic/tlb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/tlb.h +0 -0
index e402aef79c93..812110813b84 100644

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 6 lines
include/asm-generic/tlb.h +1 -1
@@ -501,7 +501,7 @@ static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb,
  */
 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
 {
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

It might not be your preferred coding style, but it is not completely pointless.

#3 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 9 lines · Peter Zijlstra

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 6 lines

*/
static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) {

include/asm-generic/tlb.h +1 -1
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

tlb_remove_page_size() is void function already. (^^)

Quoted 2 lines

It might not be your preferred coding style, but it is not completely pointless.

based on below C spec such as C17 description. i guess language C does not like this usage "return void function in void function";

C spec such as C17 have this description about return statement:
6.8.6.4:
A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.

maintainer
#4 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 11 lines · Zijun Hu
Quoted 9 lines · Peter Zijlstra

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 6 lines

*/
static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) {

include/asm-generic/tlb.h +1 -1
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

Quoted 1 line

tlb_remove_page_size() is void function already. (^^)

Yes, but if you were to change that, the above return would complain.

Quoted 5 lines
Quoted 2 lines

It might not be your preferred coding style, but it is not completely pointless.

based on below C spec such as C17 description. i guess language C does not like this usage "return void function in void function";

This is GNU extension IIRC. Note kernel uses GNU11, not C11

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#5 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 16 lines · Peter Zijlstra
Quoted 11 lines · Zijun Hu
Quoted 9 lines · Peter Zijlstra

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 6 lines

*/
static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) {

include/asm-generic/tlb.h +1 -1
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

Quoted 1 line

tlb_remove_page_size() is void function already. (^^)

Yes, but if you were to change that, the above return would complain.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

It might not be your preferred coding style, but it is not completely pointless.

based on below C spec such as C17 description. i guess language C does not like this usage "return void function in void function";

This is GNU extension IIRC. Note kernel uses GNU11, not C11

any link to share about GNU11's description for this aspect ? (^^)

#6 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 20 lines · Zijun Hu
Quoted 19 lines · Peter Zijlstra
Quoted 11 lines · Zijun Hu
Quoted 9 lines · Peter Zijlstra

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 6 lines
   */
  static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  {
include/asm-generic/tlb.h +1 -1
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
  }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

Quoted 1 line

tlb_remove_page_size() is void function already. (^^)

Yes, but if you were to change that, the above return would complain.

Quoted 3 lines
Quoted 2 lines

It might not be your preferred coding style, but it is not completely pointless.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

based on below C spec such as C17 description. i guess language C does not like this usage "return void function in void function";

This is GNU extension IIRC. Note kernel uses GNU11, not C11

any link to share about GNU11's description for this aspect ? (^^)

this is new for C17 or was there for long time?

even if this is an extension, it is very nice for generating locked wrappers, so you don't have to handle void case specially

void foo_bar(...)

{
	lockdep_assert_held(&a_lock);
	/// ...
}

// generated
void foo_bar_lock(...)

{
	scoped_guard(mutex, &a_lock)
		return foo_bar(...);
}

etc

#7 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 11 lines · Przemek Kitszel
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

It might not be your preferred coding style, but it is not completely pointless.

based on below C spec such as C17 description. i guess language C does not like this usage "return void function in void function";

This is GNU extension IIRC. Note kernel uses GNU11, not C11

any link to share about GNU11's description for this aspect ? (^^)

this is new for C17 or was there for long time?

Standard C spec has that description for long time. Standard C11 spec also has that description.

Quoted 9 lines

even if this is an extension, it is very nice for generating locked wrappers, so you don't have to handle void case specially

void foo_bar(...)
{
    lockdep_assert_held(&a_lock);
    /// ...
}

Quoted 5 lines

// generated
void foo_bar_lock(...)
{
    scoped_guard(mutex, &a_lock)
        return foo_bar(...);

above is able to be written as below:

      scoped_guard(mutex, &a_lock) {
	foo_bar(...);
	return;
      }
Quoted 1 line

}

i will list my reasons why this usage "return void function in void function" is not good in cover letter [00/18] of this series.

#8 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

In reply to Zijun Hu
Quoted 10 lines · Zijun Hu
Quoted 8 lines

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 5 lines

static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) {

include/asm-generic/tlb.h +1 -1
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

tlb_remove_page_size() is void function already. (^^)

That may be true... for now. But if that is changed in the future, then you will get an error indicating something you need to go and look at... so in that regard, it's *better* to do this ;-)

David

#9 lore raw

Re: [PATCH *-next 01/18] mm/mmu_gather: Remove needless return in void API tlb_remove_page()

Quoted 11 lines · David Howells
Quoted 9 lines · Zijun Hu
Quoted 8 lines

include/asm-generic/tlb.h static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, · line 505

Quoted 5 lines

static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) {

include/asm-generic/tlb.h +1 -1
-	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
+	tlb_remove_page_size(tlb, page, PAGE_SIZE);
 }

So I don't mind removing it, but note that that return enforces tlb_remove_page_size() has void return type.

Quoted 6 lines
Quoted 1 line

tlb_remove_page_size() is void function already. (^^)

That may be true... for now. But if that is changed in the future, then you will get an error indicating something you need to go and look at... so in that regard, it's *better* to do this ;-)

i understand your point.

if the callee tlb_remove_page_size() is in the same module with the caller tlb_remove_page. it is meaningless to watch the callee's return type.

otherwise, provided the callee is a API which is provided by other module author. once the author changes the API's return type, he/she must take effort to cleanup this weird and lots of usages, that is not nice for API provider.

this is a common issue. i will list my reasons why this usage is not good in cover letter of this series

Quoted 2 lines

David

author
#10 lore raw

PATCH 2/18 cpu: Remove needless return in void API suspend_enable_secondary_cpus()

In reply to Zijun Hu

Remove needless 'return' in void API suspend_enable_secondary_cpus() since both the API and thaw_secondary_cpus() are void functions.

---
 include/linux/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/cpu.h +1 -1
index 6a0a8f1c7c90..e3049543008b 100644
@@ -148,7 +148,7 @@ static inline int suspend_disable_secondary_cpus(void)
 }
 static inline void suspend_enable_secondary_cpus(void)
 {
-	return thaw_secondary_cpus();
+	thaw_secondary_cpus();
 }
 
 #else /* !CONFIG_PM_SLEEP_SMP */
Signature · 1 line
2.34.1
author
#11 lore raw

PATCH 3/18 crypto: api - Remove needless return in void API crypto_free_tfm()

In reply to Zijun Hu

Remove needless 'return' in void API crypto_free_tfm() since both the API and crypto_destroy_tfm() are void functions.

---
 include/linux/crypto.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/crypto.h +1 -1
index b164da5e129e..90ac1142b1a2 100644
@@ -446,7 +446,7 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm);
 
 static inline void crypto_free_tfm(struct crypto_tfm *tfm)
 {
-	return crypto_destroy_tfm(tfm, tfm);
+	crypto_destroy_tfm(tfm, tfm);
 }
 
 /*
Signature · 1 line
2.34.1
author
#12 lore raw

PATCH 4/18 crypto: scomp - Remove needless return in void API crypto_scomp_free_ctx()

In reply to Zijun Hu

Remove needless 'return' in void API crypto_scomp_free_ctx() since both the API and crypto_scomp_alg(@tfm)->free_ctx() are void functions.

---
 include/crypto/internal/scompress.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/crypto/internal/scompress.h +1 -1
index 07a10fd2d321..44130680dc0a 100644
@@ -79,7 +79,7 @@ static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm)
 static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm,
 					 void *ctx)
 {
-	return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
+	crypto_scomp_alg(tfm)->free_ctx(tfm, ctx);
 }
 
 static inline int crypto_scomp_compress(struct crypto_scomp *tfm,
Signature · 1 line
2.34.1
author
#13 lore raw

PATCH 5/18 sysfs: Remove needless return in void API sysfs_enable_ns()

In reply to Zijun Hu

Remove needless 'return' in void API sysfs_enable_ns() since both the API and kernfs_enable_ns() are void functions.

---
 include/linux/sysfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sysfs.h +1 -1
index 18f7e1fd093c..ad5015876c70 100644
@@ -491,7 +491,7 @@ int __must_check sysfs_init(void);
 
 static inline void sysfs_enable_ns(struct kernfs_node *kn)
 {
-	return kernfs_enable_ns(kn);
+	kernfs_enable_ns(kn);
 }
 
 int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid,
Signature · 1 line
2.34.1
author
#14 lore raw

PATCH 6/18 skbuff: Remove needless return in void API consume_skb()

In reply to Zijun Hu

Remove needless 'return' in void API consume_skb() since both the API and kfree_skb() are void functions.

---
 include/linux/skbuff.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/skbuff.h +1 -1
index bb2b751d274a..33bf30bc16f5 100644
@@ -1296,7 +1296,7 @@ void consume_skb(struct sk_buff *skb);
 #else
 static inline void consume_skb(struct sk_buff *skb)
 {
-	return kfree_skb(skb);
+	kfree_skb(skb);
 }
 #endif
 
Signature · 1 line
2.34.1
author
#15 lore raw

PATCH 7/18 wifi: mac80211: Remove needless return in void API _ieee80211_hw_set()

In reply to Zijun Hu

Remove needless 'return' in void API _ieee80211_hw_set() since both the API and __set_bit() are void functions.

---
 include/net/mac80211.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/mac80211.h +1 -1
index c3ed2fcff8b7..3a654e9f41db 100644
@@ -3091,7 +3091,7 @@ static inline bool _ieee80211_hw_check(struct ieee80211_hw *hw,
 static inline void _ieee80211_hw_set(struct ieee80211_hw *hw,
 				     enum ieee80211_hw_flags flg)
 {
-	return __set_bit(flg, hw->flags);
+	__set_bit(flg, hw->flags);
 }
 #define ieee80211_hw_set(hw, flg)	_ieee80211_hw_set(hw, IEEE80211_HW_##flg)
 
Signature · 1 line
2.34.1
author
#16 lore raw

PATCH 8/18 net: sched: Remove needless return in void API qdisc_watchdog_schedule_ns()

In reply to Zijun Hu

Remove needless 'return' in void API qdisc_watchdog_schedule_ns() since both the API and qdisc_watchdog_schedule_range_ns() are void functions.

---
 include/net/pkt_sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/pkt_sched.h +1 -1
index d7b7b6cd4aa1..b4d9ea54d947 100644
@@ -78,7 +78,7 @@ void qdisc_watchdog_schedule_range_ns(struct qdisc_watchdog *wd, u64 expires,
 static inline void qdisc_watchdog_schedule_ns(struct qdisc_watchdog *wd,
 					      u64 expires)
 {
-	return qdisc_watchdog_schedule_range_ns(wd, expires, 0ULL);
+	qdisc_watchdog_schedule_range_ns(wd, expires, 0ULL);
 }
 
 static inline void qdisc_watchdog_schedule(struct qdisc_watchdog *wd,
Signature · 1 line
2.34.1
author
#17 lore raw

PATCH 9/18 ipv4/igmp: Remove needless return in void API ip_mc_dec_group()

In reply to Zijun Hu

Remove needless 'return' in void API ip_mc_dec_group() since both the API and __ip_mc_dec_group() are void functions.

---
 include/linux/igmp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/igmp.h +1 -1
index 073b30a9b850..dddf90c55215 100644
@@ -135,7 +135,7 @@ extern void ip_mc_remap(struct in_device *);
 extern void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp);
 static inline void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)
 {
-	return __ip_mc_dec_group(in_dev, addr, GFP_KERNEL);
+	__ip_mc_dec_group(in_dev, addr, GFP_KERNEL);
 }
 extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
 			      gfp_t gfp);
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH 10/18 IB/rdmavt: Remove needless return in void API rvt_mod_retry_timer()

In reply to Zijun Hu

Remove needless 'return' in void API rvt_mod_retry_timer() since both the API and rvt_mod_retry_timer_ext() are void functions.

---
 include/rdma/rdmavt_qp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/rdmavt_qp.h +1 -1
index d67892944193..6b9ee610168c 100644
@@ -735,7 +735,7 @@ static inline void rvt_mod_retry_timer_ext(struct rvt_qp *qp, u8 shift)
 
 static inline void rvt_mod_retry_timer(struct rvt_qp *qp)
 {
-	return rvt_mod_retry_timer_ext(qp, 0);
+	rvt_mod_retry_timer_ext(qp, 0);
 }
 
 /**
Signature · 1 line
2.34.1
author
#19 lore raw

PATCH 11/18 ratelimit: Remove needless return in void API ratelimit_default_init()

In reply to Zijun Hu

Remove needless 'return' in void API ratelimit_default_init() since both the API and ratelimit_state_init() are void functions.

---
 include/linux/ratelimit.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/ratelimit.h +2 -2
index b17e0cd0a30c..5308cdf43056 100644
@@ -18,8 +18,8 @@ static inline void ratelimit_state_init(struct ratelimit_state *rs,
 
 static inline void ratelimit_default_init(struct ratelimit_state *rs)
 {
-	return ratelimit_state_init(rs, DEFAULT_RATELIMIT_INTERVAL,
-					DEFAULT_RATELIMIT_BURST);
+	ratelimit_state_init(rs, DEFAULT_RATELIMIT_INTERVAL,
+			     DEFAULT_RATELIMIT_BURST);
 }
 
 static inline void ratelimit_state_exit(struct ratelimit_state *rs)
Signature · 1 line
2.34.1
author
#20 lore raw

PATCH 12/18 siox: Remove needless return in void API siox_driver_unregister()

In reply to Zijun Hu

Remove needless 'return' in void API siox_driver_unregister() since both the API and driver_unregister() are void functions.

---
 include/linux/siox.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/siox.h +1 -1
index 6bfbda3f634c..31a20ba03d3a 100644
@@ -70,7 +70,7 @@ static inline int siox_driver_register(struct siox_driver *sdriver)
 
 static inline void siox_driver_unregister(struct siox_driver *sdriver)
 {
-	return driver_unregister(&sdriver->driver);
+	driver_unregister(&sdriver->driver);
 }
 
 /*
Signature · 1 line
2.34.1
author
#21 lore raw

PATCH 13/18 gpiolib: Remove needless return in two void APIs

In reply to Zijun Hu

Remove needless 'return' in the following void APIs:

gpio_set_value_cansleep()
gpio_set_value()

Since both the API and callee involved are void functions.

---
 include/linux/gpio.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/gpio.h +2 -2
index 6270150f4e29..c1ec62c11ed3 100644
@@ -91,7 +91,7 @@ static inline int gpio_get_value_cansleep(unsigned gpio)
 }
 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
 {
-	return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
+	gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
 }
 
 static inline int gpio_get_value(unsigned gpio)
@@ -100,7 +100,7 @@ static inline int gpio_get_value(unsigned gpio)
 }
 static inline void gpio_set_value(unsigned gpio, int value)
 {
-	return gpiod_set_raw_value(gpio_to_desc(gpio), value);
+	gpiod_set_raw_value(gpio_to_desc(gpio), value);
 }
 
 static inline int gpio_to_irq(unsigned gpio)
Signature · 1 line
2.34.1
#22 lore raw

Re: [PATCH *-next 13/18] gpiolib: Remove needless return in two void APIs

Quoted 10 lines · Zijun Hu

Remove needless 'return' in the following void APIs:

gpio_set_value_cansleep()
gpio_set_value()

Since both the API and callee involved are void functions.

---

That would normally make sense but we're getting that reworked[1] in this very cycle so please drop this patch from your series.

Bart

[1] https://lore.kernel.org/linux-gpio/[email protected]/

author
#23 lore raw

Re: [PATCH *-next 13/18] gpiolib: Remove needless return in two void APIs

Quoted 7 lines · Bartosz Golaszewski
Quoted 6 lines · Zijun Hu

Remove needless 'return' in the following void APIs:

gpio_set_value_cansleep()
gpio_set_value()

Quoted 8 lines
Quoted 4 lines

Since both the API and callee involved are void functions.

---

That would normally make sense but we're getting that reworked[1] in this very cycle so please drop this patch from your series.

sure, will drop it in next revision.

Quoted 3 lines

Bart

[1] https://lore.kernel.org/linux-gpio/[email protected]/

author
#24 lore raw

PATCH 14/18 PM: wakeup: Remove needless return in three void APIs

In reply to Zijun Hu

Remove needless 'return' in the following void APIs:

__pm_wakeup_event()
pm_wakeup_event()
pm_wakeup_hard_event()

Since both the API and callee involved are void functions.

---
 include/linux/pm_wakeup.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/pm_wakeup.h +3 -3
index d501c09c60cd..51e0e8dd5f9e 100644
@@ -205,17 +205,17 @@ static inline void device_set_awake_path(struct device *dev)
 
 static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
 {
-	return pm_wakeup_ws_event(ws, msec, false);
+	pm_wakeup_ws_event(ws, msec, false);
 }
 
 static inline void pm_wakeup_event(struct device *dev, unsigned int msec)
 {
-	return pm_wakeup_dev_event(dev, msec, false);
+	pm_wakeup_dev_event(dev, msec, false);
 }
 
 static inline void pm_wakeup_hard_event(struct device *dev)
 {
-	return pm_wakeup_dev_event(dev, 0, true);
+	pm_wakeup_dev_event(dev, 0, true);
 }
 
 /**
Signature · 1 line
2.34.1
maintainer Applied
#25 lore raw

Re: [PATCH *-next 14/18] PM: wakeup: Remove needless return in three void APIs

Quoted 31 lines · Zijun Hu

Remove needless 'return' in the following void APIs:

__pm_wakeup_event()
pm_wakeup_event()
pm_wakeup_hard_event()

Since both the API and callee involved are void functions.

---
 include/linux/pm_wakeup.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/pm_wakeup.h +2 -2
index d501c09c60cd..51e0e8dd5f9e 100644
@@ -205,17 +205,17 @@ static inline void device_set_awake_path(struct device *dev)
 
 static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
 {
-       return pm_wakeup_ws_event(ws, msec, false);
+       pm_wakeup_ws_event(ws, msec, false);
 }
 
 static inline void pm_wakeup_event(struct device *dev, unsigned int msec)
 {
-       return pm_wakeup_dev_event(dev, msec, false);
+       pm_wakeup_dev_event(dev, msec, false);
 }

include/linux/pm_wakeup.h static inline void device_set_awake_path(struct device *dev)

Quoted 10 lines
include/linux/pm_wakeup.h +1 -2
 
 static inline void pm_wakeup_hard_event(struct device *dev)
 {
-       return pm_wakeup_dev_event(dev, 0, true);
+       pm_wakeup_dev_event(dev, 0, true);
 }
 
 /**
 
--

Applied as 6.15 material, thanks!

author
#26 lore raw

PATCH 15/18 mfd: db8500-prcmu: Remove needless return in three void APIs

In reply to Zijun Hu

Remove needless 'return' in the following void APIs:

prcmu_early_init()
prcmu_system_reset()
prcmu_modem_reset()

Since both the API and callee involved are void functions.

---
 include/linux/mfd/dbx500-prcmu.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/mfd/dbx500-prcmu.h +3 -3
index dd0fc891b228..98567623c9df 100644
@@ -215,7 +215,7 @@ struct prcmu_fw_version {
 
 static inline void prcmu_early_init(void)
 {
-	return db8500_prcmu_early_init();
+	db8500_prcmu_early_init();
 }
 
 static inline int prcmu_set_power_state(u8 state, bool keep_ulp_clk,
@@ -302,7 +302,7 @@ static inline int prcmu_request_ape_opp_100_voltage(bool enable)
 
 static inline void prcmu_system_reset(u16 reset_code)
 {
-	return db8500_prcmu_system_reset(reset_code);
+	db8500_prcmu_system_reset(reset_code);
 }
 
 static inline u16 prcmu_get_reset_code(void)
@@ -314,7 +314,7 @@ int prcmu_ac_wake_req(void);
 void prcmu_ac_sleep_req(void);
 static inline void prcmu_modem_reset(void)
 {
-	return db8500_prcmu_modem_reset();
+	db8500_prcmu_modem_reset();
 }
 
 static inline bool prcmu_is_ac_wake_requested(void)
Signature · 1 line
2.34.1
Reviewed-by on v1 15/18
#27 lore raw

Re: [PATCH *-next 15/18] mfd: db8500-prcmu: Remove needless return in three void APIs

Quoted 9 lines · Zijun Hu

Remove needless 'return' in the following void APIs:

prcmu_early_init()
prcmu_system_reset()
prcmu_modem_reset()

Since both the API and callee involved are void functions.

Yours,
Linus Walleij

maintainer Applied
#28 lore raw

Re: (subset) [PATCH *-next 15/18] mfd: db8500-prcmu: Remove needless return in three void APIs

In reply to Zijun Hu
Quoted 9 lines · Zijun Hu

Remove needless 'return' in the following void APIs:

prcmu_early_init()
prcmu_system_reset()
prcmu_modem_reset()

Since both the API and callee involved are void functions.

[...]

Applied, thanks!

[15/18] mfd: db8500-prcmu: Remove needless return in three void APIs

        commit: ccf5c7a8e5b9fe7c36d8c384f8f7c495f45c63a0

--
Lee Jones [李琼斯]

author
#29 lore raw

PATCH 16/18 rhashtable: Remove needless return in three void APIs

In reply to Zijun Hu

Remove needless 'return' in the following void APIs:

rhltable_walk_enter()
rhltable_free_and_destroy()
rhltable_destroy()

Since both the API and callee involved are void functions.

---
 include/linux/rhashtable.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/rhashtable.h +3 -3
index 8463a128e2f4..6c85b28ea30b 100644
@@ -1259,7 +1259,7 @@ static inline int rhashtable_replace_fast(
 static inline void rhltable_walk_enter(struct rhltable *hlt,
 				       struct rhashtable_iter *iter)
 {
-	return rhashtable_walk_enter(&hlt->ht, iter);
+	rhashtable_walk_enter(&hlt->ht, iter);
 }
 
 /**
@@ -1275,12 +1275,12 @@ static inline void rhltable_free_and_destroy(struct rhltable *hlt,
 							     void *arg),
 					     void *arg)
 {
-	return rhashtable_free_and_destroy(&hlt->ht, free_fn, arg);
+	rhashtable_free_and_destroy(&hlt->ht, free_fn, arg);
 }
 
 static inline void rhltable_destroy(struct rhltable *hlt)
 {
-	return rhltable_free_and_destroy(hlt, NULL, NULL);
+	rhltable_free_and_destroy(hlt, NULL, NULL);
 }
 
 #endif /* _LINUX_RHASHTABLE_H */
Signature · 1 line
2.34.1
author
#30 lore raw

PATCH 17/18 dma-mapping: Remove needless return in five void APIs

In reply to Zijun Hu

Remove needless 'return' in the following void APIs:

dma_unmap_single_attrs()
dma_sync_single_range_for_cpu()
dma_sync_single_range_for_device()
dma_free_coherent()
dma_free_wc()

Since both the API and callee involved are void functions.

---
 include/linux/dma-mapping.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/dma-mapping.h +6 -6
index b79925b1c433..a5de6ecaace3 100644
@@ -388,21 +388,21 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
 static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
 		size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
-	return dma_unmap_page_attrs(dev, addr, size, dir, attrs);
+	dma_unmap_page_attrs(dev, addr, size, dir, attrs);
 }
 
 static inline void dma_sync_single_range_for_cpu(struct device *dev,
 		dma_addr_t addr, unsigned long offset, size_t size,
 		enum dma_data_direction dir)
 {
-	return dma_sync_single_for_cpu(dev, addr + offset, size, dir);
+	dma_sync_single_for_cpu(dev, addr + offset, size, dir);
 }
 
 static inline void dma_sync_single_range_for_device(struct device *dev,
 		dma_addr_t addr, unsigned long offset, size_t size,
 		enum dma_data_direction dir)
 {
-	return dma_sync_single_for_device(dev, addr + offset, size, dir);
+	dma_sync_single_for_device(dev, addr + offset, size, dir);
 }
 
 /**
@@ -478,7 +478,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
 static inline void dma_free_coherent(struct device *dev, size_t size,
 		void *cpu_addr, dma_addr_t dma_handle)
 {
-	return dma_free_attrs(dev, size, cpu_addr, dma_handle, 0);
+	dma_free_attrs(dev, size, cpu_addr, dma_handle, 0);
 }
 
 
@@ -606,8 +606,8 @@ static inline void *dma_alloc_wc(struct device *dev, size_t size,
 static inline void dma_free_wc(struct device *dev, size_t size,
 			       void *cpu_addr, dma_addr_t dma_addr)
 {
-	return dma_free_attrs(dev, size, cpu_addr, dma_addr,
-			      DMA_ATTR_WRITE_COMBINE);
+	dma_free_attrs(dev, size, cpu_addr, dma_addr,
+		       DMA_ATTR_WRITE_COMBINE);
 }
 
 static inline int dma_mmap_wc(struct device *dev,
Signature · 1 line
2.34.1
author
#31 lore raw

PATCH 18/18 mtd: nand: Do not return void function in void function

In reply to Zijun Hu

In the following three void APIs:

nanddev_pos_next_lun()
nanddev_pos_next_eraseblock()
nanddev_pos_next_page()

For void function void func(...), convert weird statement:

	return func(...);
"to":
	func(...);
	return;
---
 include/linux/mtd/nand.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
include/linux/mtd/nand.h +12 -6
index 0e2f228e8b4a..8e3f6cca0b24 100644
@@ -863,8 +863,10 @@ static inline void nanddev_pos_next_target(struct nand_device *nand,
 static inline void nanddev_pos_next_lun(struct nand_device *nand,
 					struct nand_pos *pos)
 {
-	if (pos->lun >= nand->memorg.luns_per_target - 1)
-		return nanddev_pos_next_target(nand, pos);
+	if (pos->lun >= nand->memorg.luns_per_target - 1) {
+		nanddev_pos_next_target(nand, pos);
+		return;
+	}
 
 	pos->lun++;
 	pos->page = 0;
@@ -883,8 +885,10 @@ static inline void nanddev_pos_next_lun(struct nand_device *nand,
 static inline void nanddev_pos_next_eraseblock(struct nand_device *nand,
 					       struct nand_pos *pos)
 {
-	if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1)
-		return nanddev_pos_next_lun(nand, pos);
+	if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1) {
+		nanddev_pos_next_lun(nand, pos);
+		return;
+	}
 
 	pos->eraseblock++;
 	pos->page = 0;
@@ -902,8 +906,10 @@ static inline void nanddev_pos_next_eraseblock(struct nand_device *nand,
 static inline void nanddev_pos_next_page(struct nand_device *nand,
 					 struct nand_pos *pos)
 {
-	if (pos->page >= nand->memorg.pages_per_eraseblock - 1)
-		return nanddev_pos_next_eraseblock(nand, pos);
+	if (pos->page >= nand->memorg.pages_per_eraseblock - 1) {
+		nanddev_pos_next_eraseblock(nand, pos);
+		return;
+	}
 
 	pos->page++;
 }
Signature · 1 line
2.34.1
#32 lore raw
In reply to Zijun Hu
Quoted 27 lines · Zijun Hu

This patch series is to remove weird and needless 'return' for void APIs under include/ with the following pattern:

api_header.h:

void api_func_a(...);

static inline void api_func_b(...)

{
	return api_func_a(...);
}

Remove the needless 'return' in api_func_b().

---
Zijun Hu (18):
mm/mmu_gather: Remove needless return in void API tlb_remove_page()
cpu: Remove needless return in void API suspend_enable_secondary_cpus()
crypto: api - Remove needless return in void API crypto_free_tfm()
crypto: scomp - Remove needless return in void API crypto_scomp_free_ctx()
sysfs: Remove needless return in void API sysfs_enable_ns()
skbuff: Remove needless return in void API consume_skb()
wifi: mac80211: Remove needless return in void API _ieee80211_hw_set()
net: sched: Remove needless return in void API qdisc_watchdog_schedule_ns() ipv4/igmp: Remove needless return in void API ip_mc_dec_group() IB/rdmavt: Remove needless return in void API rvt_mod_retry_timer()

Quoted 8 lines

ratelimit: Remove needless return in void API ratelimit_default_init()
siox: Remove needless return in void API siox_driver_unregister()
gpiolib: Remove needless return in two void APIs
PM: wakeup: Remove needless return in three void APIs
mfd: db8500-prcmu: Remove needless return in three void APIs
rhashtable: Remove needless return in three void APIs
dma-mapping: Remove needless return in five void APIs
mtd: nand: Do not return void function in void function

These span loads of different subsystems, please just submit them all to the different subsystems directly, not as one big patch series which none of us could take individually.

thanks,

greg k-h

author
#33 lore raw
Quoted 4 lines · Greg Kroah-Hartman

These span loads of different subsystems, please just submit them all to the different subsystems directly, not as one big patch series which none of us could take individually.

sure. will do it as you suggest.
thank you.

Quoted 3 lines

thanks,

greg k-h

maintainer
#34 lore raw
In reply to Zijun Hu
Quoted 7 lines · Zijun Hu

This patch series is to remove weird and needless 'return' for void APIs under include/ with the following pattern:

api_header.h:

void api_func_a(...);

Quoted 8 lines

static inline void api_func_b(...)

{
	return api_func_a(...);
}

Remove the needless 'return' in api_func_b().

I have no objection to the changes, but I think you should describe the motivation for them beyond them being 'weird'.

Do these 'return' statements get in the way of some other work you are doing? Is there a compiler warning you want to enable to ensure they don't come back? Is this all of the instances in the kernel or just the ones you found by inspection?

Arnd

#35 lore raw
Quoted 12 lines · Arnd Bergmann
Quoted 12 lines

This patch series is to remove weird and needless 'return' for void APIs under include/ with the following pattern:

api_header.h:

void api_func_a(...);

static inline void api_func_b(...)

{
	return api_func_a(...);
}
Quoted 6 lines
Quoted 3 lines

Remove the needless 'return' in api_func_b().

I have no objection to the changes, but I think you should describe the motivation for them beyond them being 'weird'.

yes. C spec such as C17 have this description about return statement:

6.8.6.4:
A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.

do we need to treat below return statement as bad code style ?

void api_func_a(...);
void api_func_b(...) {
...
return api_func_a(...); // return void function in void func
...
}

Quoted 5 lines

Do these 'return' statements get in the way of some other work you are doing? Is there a compiler warning you want to enable to ensure they don't come back? Is this all of the instances in the kernel or just the ones you found by inspection?

actually, i find this weird return usage by reading code by accident in driver core firstly:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=driver-core-testing&id=a44073c28bc6d4118891d61e31c9fa9dc4333dc0

then i check folder include/ and work out this patch series.

not sure if there are still such instances in current kernel tree.

#36 lore raw
In reply to Zijun Hu
Quoted 55 lines · On Fri, 21 Feb 2025 05:02:05 -0800 Zijun Hu <[email protected]> wrote:

This patch series is to remove weird and needless 'return' for void APIs under include/ with the following pattern:

api_header.h:

void api_func_a(...);

static inline void api_func_b(...)

{
	return api_func_a(...);
}

Remove the needless 'return' in api_func_b().

---
Zijun Hu (18):
mm/mmu_gather: Remove needless return in void API tlb_remove_page()
cpu: Remove needless return in void API suspend_enable_secondary_cpus()
crypto: api - Remove needless return in void API crypto_free_tfm()
crypto: scomp - Remove needless return in void API crypto_scomp_free_ctx()
sysfs: Remove needless return in void API sysfs_enable_ns()
skbuff: Remove needless return in void API consume_skb()
wifi: mac80211: Remove needless return in void API _ieee80211_hw_set()
net: sched: Remove needless return in void API qdisc_watchdog_schedule_ns() ipv4/igmp: Remove needless return in void API ip_mc_dec_group() IB/rdmavt: Remove needless return in void API rvt_mod_retry_timer()
ratelimit: Remove needless return in void API ratelimit_default_init()
siox: Remove needless return in void API siox_driver_unregister()
gpiolib: Remove needless return in two void APIs
PM: wakeup: Remove needless return in three void APIs
mfd: db8500-prcmu: Remove needless return in three void APIs
rhashtable: Remove needless return in three void APIs
dma-mapping: Remove needless return in five void APIs
mtd: nand: Do not return void function in void function

 include/asm-generic/tlb.h           |  2 +-
 include/crypto/internal/scompress.h |  2 +-
 include/linux/cpu.h                 |  2 +-
 include/linux/crypto.h              |  2 +-
 include/linux/dma-mapping.h         | 12 ++++++------
 include/linux/gpio.h                |  4 ++--
 include/linux/igmp.h                |  2 +-
 include/linux/mfd/dbx500-prcmu.h    |  6 +++---
 include/linux/mtd/nand.h            | 18 ++++++++++++------
 include/linux/pm_wakeup.h           |  6 +++---
 include/linux/ratelimit.h           |  4 ++--
 include/linux/rhashtable.h          |  6 +++---
 include/linux/siox.h                |  2 +-
 include/linux/skbuff.h              |  2 +-
 include/linux/sysfs.h               |  2 +-
 include/net/mac80211.h              |  2 +-
 include/net/pkt_sched.h             |  2 +-
 include/rdma/rdmavt_qp.h            |  2 +-
 18 files changed, 42 insertions(+), 36 deletions(-)
Quoted 5 lines

---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250221-rmv_return-f1dc82d492f0

Best regards,

Is this something that could be done with a coccinelle script?

maintainer
#37 lore raw
Quoted 3 lines · Stephen Hemminger

Is this something that could be done with a coccinelle script?

Almost enough to do this:

@@
identifier fn;
expression E;
@@
void fn(...)
{
...
-return
E;
}

It takes a long time to run though, and does some wrong things as well:
if the return is in the middle of the function, it still matches and removes it erroneously.

johannes

#38 lore raw
Quoted 17 lines · Johannes Berg
Quoted 2 lines · Stephen Hemminger

Is this something that could be done with a coccinelle script?

Almost enough to do this:

@@
identifier fn;
expression E;
@@
void fn(...)
{
...
-return
E;
}

Quoted 3 lines

It takes a long time to run though, and does some wrong things as well:
if the return is in the middle of the function, it still matches and removes it erroneously.

if return is in the middle, we may need to convert the return statement in to two statement as [PATCH 18/18] does:
https://lore.kernel.org/all/[email protected]/

namely, Convert "return func(...);" to "func(...); return;"

C spec such as C17 have this description about return statement:
6.8.6.4:
A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.

so, do we need to treat "return void function in void function" as bad code style and make coccinelle script check this bad usage?

#39 lore raw
In reply to Zijun Hu
Quoted 6 lines · Zijun Hu

void api_func_a(...);

static inline void api_func_b(...)

{
	return api_func_a(...);
}

The Usage : Return void function in void function

IMO, perhaps, the usage is not good since:

A) STD C does not like the usage, and i find GCC has no description about the usage.
C11/C17: 6.8.6.4 The return statement
"A return statement with an expression shall not appear in a
function whose return type is void"

B) According to discussion, the usage have function that return type of the callee api_func_a() is monitored. but this function has below
shortcoming as well:

the monitor is not needed if the caller api_func_b() is in the same module with the callee api_func_a(), otherwise, provided the callee is a API and provided by author of other module. the author needs to clean up lot of usages of the API if he/she changes the API's return type from void to any other type, so it is not nice to API provider.

C) perhaps, most ordinary developers don't known the function mentioned by B), and also feel strange for the usage

maintainer
#40 lore raw
Quoted 10 lines · Zijun Hu
Quoted 6 lines · Zijun Hu

void api_func_a(...);

static inline void api_func_b(...)

{
	return api_func_a(...);
}

The Usage : Return void function in void function

Quoted 7 lines

IMO, perhaps, the usage is not good since:

A) STD C does not like the usage, and i find GCC has no description about the usage.
C11/C17: 6.8.6.4 The return statement
"A return statement with an expression shall not appear in a
function whose return type is void"

We really don't use STD C, the kernel is littered with extensions.

Quoted 4 lines

B) According to discussion, the usage have function that return type of the callee api_func_a() is monitored. but this function has below
shortcoming as well:

Quoted 8 lines

the monitor is not needed if the caller api_func_b() is in the same module with the callee api_func_a(), otherwise, provided the callee is a API and provided by author of other module. the author needs to clean up lot of usages of the API if he/she changes the API's return type from void to any other type, so it is not nice to API provider.

C) perhaps, most ordinary developers don't known the function mentioned by B), and also feel strange for the usage

It is quite common to do kernel wide updates using scripts / cocinelle.

If you have a specialization that wraps a function to fill out a default value, then you want the return types to keep matching.

Ex.

return_type foo(type1 a1, type2 a2);

return_type my_foo(type1 a1)

{
	return foo(a1, value);
}

is a normal thing to do. The whole STD C cannot return void bollocks breaks that when return_type := void, so in that regards I would call this a STD C defect.

#41 lore raw
Quoted 11 lines · Peter Zijlstra
Quoted 2 lines

C) perhaps, most ordinary developers don't known the function mentioned by B), and also feel strange for the usage

It is quite common to do kernel wide updates using scripts / cocinelle.

If you have a specialization that wraps a function to fill out a default value, then you want the return types to keep matching.

Ex.

return_type foo(type1 a1, type2 a2);

Quoted 8 lines

return_type my_foo(type1 a1)

{
	return foo(a1, value);
}

is a normal thing to do. The whole STD C cannot return void bollocks breaks that when return_type := void, so in that regards I would call this a STD C defect.

The usage is a GCC extension.
but the usage is prone to be used within *inappropriate* context, take this patch series for an example:

1) both foo() and my_foo() are in the same module
2) or it seems return type void is the best type for foo(). so no good reason to track its type.