Skip to contentSkip to conversation

dm-pcache: built-in support and metadata hardening

PATCH Superseded Li Chen 4 participants 14 messages Nov 5, 2025 – Nov 10, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Chen

author
#0 lore raw

cover dm-pcache: built-in support and metadata hardening

From: Li Chen <[email protected]>

This three-patch series tidies dm-pcache’s build glue and tightens the metadata scan.

Patch 1 allow dm-pcache to be linked into vmlinux and avoids clashing with the sunrpc cache_flush() by using obj-$(CONFIG_DM_PCACHE) and renaming the helper across the tree.

Patch 2 drops a redundant recomputation of the metadata slot pointer while walking headers.

Patch 3 zero-allocates a temporary buffer so callers never see stale metadata, relies on __free(kvfree) for cleanup, and only copies back once a valid record is found.

Thanks for your review.

Li Chen (3):
dm-pcache: allow built-in build and rename flush helper
dm-pcache: reuse meta_addr in pcache_meta_find_latest
dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest()

 drivers/md/dm-pcache/Makefile          |  2 +-
 drivers/md/dm-pcache/cache.c           |  2 +-
 drivers/md/dm-pcache/cache.h           |  2 +-
 drivers/md/dm-pcache/cache_req.c       |  6 +++---
 drivers/md/dm-pcache/pcache_internal.h | 15 ++++++++++-----
 5 files changed, 16 insertions(+), 11 deletions(-)
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 1/3 dm-pcache: allow built-in build and rename flush helper

From: Li Chen <[email protected]>

CONFIG_BCACHE is tristate, so dm-pcache can also be built-in. Switch the Makefile to use obj-$(CONFIG_DM_PCACHE) so the target can be linked into vmlinux instead of always being a loadable module.

Also rename cache_flush() to pcache_cache_flush() to avoid a global symbol clash with sunrpc/cache.c's cache_flush().

---
 drivers/md/dm-pcache/Makefile    | 2 +-
 drivers/md/dm-pcache/cache.c     | 2 +-
 drivers/md/dm-pcache/cache.h     | 2 +-
 drivers/md/dm-pcache/cache_req.c | 6 +++---
 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/md/dm-pcache/Makefile +1 -1
index 86776e4acad24..cedfd38854f63 100644
@@ -1,3 +1,3 @@
 dm-pcache-y := dm_pcache.o cache_dev.o segment.o backing_dev.o cache.o cache_gc.o cache_writeback.o cache_segment.o cache_key.o cache_req.o
 
-obj-m += dm-pcache.o
+obj-$(CONFIG_DM_PCACHE) += dm-pcache.o
drivers/md/dm-pcache/cache.c +1 -1
index d8e92367d9470..d516d49042272 100644
@@ -411,7 +411,7 @@ void pcache_cache_stop(struct dm_pcache *pcache)
 {
 	struct pcache_cache *cache = &pcache->cache;
 
-	cache_flush(cache);
+	pcache_cache_flush(cache);
 
 	cancel_delayed_work_sync(&cache->gc_work);
 	flush_work(&cache->clean_work);
drivers/md/dm-pcache/cache.h +1 -1
index 1136d86958c8c..27613b56be54c 100644
@@ -339,7 +339,7 @@ void cache_seg_put(struct pcache_cache_segment *cache_seg);
 void cache_seg_set_next_seg(struct pcache_cache_segment *cache_seg, u32 seg_id);
 
 /* cache request*/
-int cache_flush(struct pcache_cache *cache);
+int pcache_cache_flush(struct pcache_cache *cache);
 void miss_read_end_work_fn(struct work_struct *work);
 int pcache_cache_handle_req(struct pcache_cache *cache, struct pcache_request *pcache_req);
 
drivers/md/dm-pcache/cache_req.c +3 -3
index 27f94c1fa968c..7854a30e07b7f 100644
@@ -790,7 +790,7 @@ static int cache_write(struct pcache_cache *cache, struct pcache_request *pcache
 }
 
 /**
- * cache_flush - Flush all ksets to persist any pending cache data
+ * pcache_cache_flush - Flush all ksets to persist any pending cache data
  * @cache: Pointer to the cache structure
  *
  * This function iterates through all ksets associated with the provided `cache`
@@ -802,7 +802,7 @@ static int cache_write(struct pcache_cache *cache, struct pcache_request *pcache
  * the respective error code, preventing the flush operation from proceeding to
  * subsequent ksets.
  */
-int cache_flush(struct pcache_cache *cache)
+int pcache_cache_flush(struct pcache_cache *cache)
 {
 	struct pcache_cache_kset *kset;
 	int ret;
@@ -827,7 +827,7 @@ int pcache_cache_handle_req(struct pcache_cache *cache, struct pcache_request *p
 	struct bio *bio = pcache_req->bio;
 
 	if (unlikely(bio->bi_opf & REQ_PREFLUSH))
-		return cache_flush(cache);
+		return pcache_cache_flush(cache);
 
 	if (bio_data_dir(bio) == READ)
 		return cache_read(cache, pcache_req);
Signature · 1 line
2.51.0
author
#2 lore raw

PATCH 2/3 dm-pcache: reuse meta_addr in pcache_meta_find_latest

In reply to Li Chen

From: Li Chen <[email protected]>

pcache_meta_find_latest() already computes the metadata address as meta_addr. Reuse that instead of recomputing.

---
 drivers/md/dm-pcache/pcache_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-pcache/pcache_internal.h +1 -1
index d427e534727ce..b7a3319d2bd3e 100644
@@ -99,7 +99,7 @@ static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_head
 		/* Update latest if a more recent sequence is found */
 		if (!latest || pcache_meta_seq_after(meta->seq, seq_latest)) {
 			seq_latest = meta->seq;
-			latest = (void *)header + (i * meta_max_size);
+			latest = meta_addr;
 		}
 	}
 
Signature · 1 line
2.51.0
author
#3 lore raw

PATCH 3/3 dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest()

In reply to Li Chen

From: Li Chen <[email protected]>

Before this change pcache_meta_find_latest() was copying each slot directly into meta_ret while scanning. If no valid slot was found and the function returned NULL, meta_ret still held whatever was last copied (possibly CRC-bad). Later users (e.g. cache_segs_init) could mistakenly trust that data.

Allocate a temporary buffer instead and only populate meta_ret after a valid/latest header is found. If no valid header exists we return NULL without touching meta_ret.

Also add __free(kvfree) so the temporary buffer is always freed, and include the needed headers.

---
 drivers/md/dm-pcache/pcache_internal.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/md/dm-pcache/pcache_internal.h +9 -4
index b7a3319d2bd3e..ac28f9dd2986f 100644
@@ -4,6 +4,8 @@
 
 #include <linux/delay.h>
 #include <linux/crc32c.h>
+#include <linux/slab.h>
+#include <linux/cleanup.h>
 
 #define pcache_err(fmt, ...)							\
 	pr_err("dm-pcache: %s:%u " fmt, __func__, __LINE__, ##__VA_ARGS__)
@@ -79,14 +81,17 @@ static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_head
 					u32 meta_size, u32 meta_max_size,
 					void *meta_ret)
 {
-	struct pcache_meta_header *meta, *latest = NULL;
+	struct pcache_meta_header *latest = NULL;
+	struct pcache_meta_header *meta __free(kvfree);
 	u32 i, seq_latest = 0;
-	void *meta_addr;
 
-	meta = meta_ret;
+	meta = kvzalloc(meta_size, GFP_KERNEL);
+	if (!meta)
+		return ERR_PTR(-ENOMEM);
 
 	for (i = 0; i < PCACHE_META_INDEX_MAX; i++) {
-		meta_addr = (void *)header + (i * meta_max_size);
+		void *meta_addr = (void *)header + (i * meta_max_size);
+
 		if (copy_mc_to_kernel(meta, meta_addr, meta_size)) {
 			pcache_err("hardware memory error when copy meta");
 			return ERR_PTR(-EIO);
Signature · 1 line
2.51.0
maintainer
#4 lore raw

Re: [PATCH 3/3] dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest()

Hi Li,

    It seems you sent the same patch again, shoud it be V2 instead?

Thanx

Quoted 55 lines · Li Chen

From: Li Chen <[email protected]>

Before this change pcache_meta_find_latest() was copying each slot directly into meta_ret while scanning. If no valid slot was found and the function returned NULL, meta_ret still held whatever was last copied (possibly CRC-bad). Later users (e.g. cache_segs_init) could mistakenly trust that data.

Allocate a temporary buffer instead and only populate meta_ret after a valid/latest header is found. If no valid header exists we return NULL without touching meta_ret.

Also add __free(kvfree) so the temporary buffer is always freed, and include the needed headers.

---
  drivers/md/dm-pcache/pcache_internal.h | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)
drivers/md/dm-pcache/pcache_internal.h +9 -4
index b7a3319d2bd3e..ac28f9dd2986f 100644
@@ -4,6 +4,8 @@
 
  #include <linux/delay.h>
  #include <linux/crc32c.h>
+#include <linux/slab.h>
+#include <linux/cleanup.h>
 
  #define pcache_err(fmt, ...)							\
  	pr_err("dm-pcache: %s:%u " fmt, __func__, __LINE__, ##__VA_ARGS__)
@@ -79,14 +81,17 @@ static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_head
  					u32 meta_size, u32 meta_max_size,
  					void *meta_ret)
  {
-	struct pcache_meta_header *meta, *latest = NULL;
+	struct pcache_meta_header *latest = NULL;
+	struct pcache_meta_header *meta __free(kvfree);
  	u32 i, seq_latest = 0;
-	void *meta_addr;
 
-	meta = meta_ret;
+	meta = kvzalloc(meta_size, GFP_KERNEL);
+	if (!meta)
+		return ERR_PTR(-ENOMEM);
 
  	for (i = 0; i < PCACHE_META_INDEX_MAX; i++) {
-		meta_addr = (void *)header + (i * meta_max_size);
+		void *meta_addr = (void *)header + (i * meta_max_size);
+
  		if (copy_mc_to_kernel(meta, meta_addr, meta_size)) {
  			pcache_err("hardware memory error when copy meta");
  			return ERR_PTR(-EIO);
author
#5 lore raw

Re: [PATCH 3/3] dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest()

Hi Dongsheng,

---- On Mon, 10 Nov 2025 19:18:38 +0800 Dongsheng Yang <[email protected]> wrote ---

Quoted 3 lines

Hi Li,

It seems you sent the same patch again, shoud it be V2 instead?

Apologies for the duplicate patchset. I mistakenly included pcache in that GCC plugin series. I will send the pcache v2 patchset tomorrow.

Regards,

Li​

author
#6 lore raw

cover Add cleanup_plugin for detecting problematic cleanup patterns

In reply to Li Chen

From: Li Chen <[email protected]>

Hello,

This patch series introduces a new GCC plugin called cleanup_plugin that warns developers about problematic patterns when using variables with __attribute__((cleanup(...))). The plugin addresses concerns documented in include/linux/cleanup.h regarding resource leaks and interdependency issues.

The cleanup attribute helpers (__free, DEFINE_FREE, etc.) are designed to automatically clean up resources when variables go out of scope, following LIFO (last in first out) ordering. However, certain patterns can lead to subtle bugs:

1. Uninitialized cleanup variables: Variables declared with cleanup attributes but not initialized can cause issues when cleanup functions are called on undefined values.

2. NULL-initialized cleanup variables: The "__free(...) = NULL" pattern at function top can cause interdependency problems, especially when combined with guards or multiple cleanup variables, as the cleanup may run in unexpected contexts.

The plugin detects both of these problematic patterns and provides clear warnings to developers, helping prevent incorrect cleanup ordering. Importantly, the plugin's warnings are not converted
to errors by -Werror, allowing builds to continue while still alerting developers to potential issues.

The plugin is enabled by default as it provides valuable compile-time feedback without impacting build performance.

Li Chen (2):
gcc-plugins: add cleanup_plugin for uninitialized cleanup detection
gcc-plugins: cleanup_plugin: detect NULL init

 scripts/Makefile.gcc-plugins         |   1 +
 scripts/gcc-plugins/Kconfig          |   6 +
 scripts/gcc-plugins/cleanup_plugin.c | 204 +++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100644 scripts/gcc-plugins/cleanup_plugin.c
Signature · 1 line
2.51.0
author
#7 lore raw

Re: [RFC PATCH 0/2] Add cleanup_plugin for detecting problematic cleanup patterns

+Peter, Dan, and Bjorn

(My apologies for the oversight)

---- On Wed, 05 Nov 2025 16:46:55 +0800 Li Chen <[email protected]> wrote ---

Quoted 37 lines

From: Li Chen <[email protected]>

Hello,

This patch series introduces a new GCC plugin called cleanup_plugin that warns developers about problematic patterns when using variables with __attribute__((cleanup(...))). The plugin addresses concerns documented in include/linux/cleanup.h regarding resource leaks and interdependency issues.

The cleanup attribute helpers (__free, DEFINE_FREE, etc.) are designed to automatically clean up resources when variables go out of scope, following LIFO (last in first out) ordering. However, certain patterns can lead to subtle bugs:

1. Uninitialized cleanup variables: Variables declared with cleanup attributes but not initialized can cause issues when cleanup functions are called on undefined values.

2. NULL-initialized cleanup variables: The "__free(...) = NULL" pattern at function top can cause interdependency problems, especially when combined with guards or multiple cleanup variables, as the cleanup may run in unexpected contexts.

The plugin detects both of these problematic patterns and provides clear warnings to developers, helping prevent incorrect cleanup ordering. Importantly, the plugin's warnings are not converted
to errors by -Werror, allowing builds to continue while still alerting developers to potential issues.

The plugin is enabled by default as it provides valuable compile-time feedback without impacting build performance.

Li Chen (2):
gcc-plugins: add cleanup_plugin for uninitialized cleanup detection
gcc-plugins: cleanup_plugin: detect NULL init

Quoted 10 lines
 scripts/Makefile.gcc-plugins         |   1 +
 scripts/gcc-plugins/Kconfig          |   6 +
 scripts/gcc-plugins/cleanup_plugin.c | 204 +++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
 create mode 100644 scripts/gcc-plugins/cleanup_plugin.c
Signature · 1 line
2.51.0

Regards,

Li​

#8 lore raw

Re: [RFC PATCH 0/2] Add cleanup_plugin for detecting problematic cleanup patterns

Quoted 37 lines · Li Chen

+Peter, Dan, and Bjorn

(My apologies for the oversight)

---- On Wed, 05 Nov 2025 16:46:55 +0800 Li Chen <[email protected]> wrote ---

Quoted 32 lines

From: Li Chen <[email protected]>

Hello,

This patch series introduces a new GCC plugin called cleanup_plugin that warns developers about problematic patterns when using variables with __attribute__((cleanup(...))). The plugin addresses concerns documented in include/linux/cleanup.h regarding resource leaks and interdependency issues.

The cleanup attribute helpers (__free, DEFINE_FREE, etc.) are designed to automatically clean up resources when variables go out of scope, following LIFO (last in first out) ordering. However, certain patterns can lead to subtle bugs:

1. Uninitialized cleanup variables: Variables declared with cleanup attributes but not initialized can cause issues when cleanup functions are called on undefined values.

2. NULL-initialized cleanup variables: The "__free(...) = NULL" pattern at function top can cause interdependency problems, especially when combined with guards or multiple cleanup variables, as the cleanup may run in unexpected contexts.

The plugin detects both of these problematic patterns and provides clear warnings to developers, helping prevent incorrect cleanup ordering. Importantly, the plugin's warnings are not converted
to errors by -Werror, allowing builds to continue while still alerting developers to potential issues.

The plugin is enabled by default as it provides valuable compile-time feedback without impacting build performance.

IIRC GCC also allow dumb stuff like gotos into the scope of a cleanup variable, where clang will fail the compile. Does this plugin also fix this?

author
#9 lore raw

Re: [RFC PATCH 0/2] Add cleanup_plugin for detecting problematic cleanup patterns

Hi Peter,

---- On Wed, 05 Nov 2025 17:49:04 +0800 Peter Zijlstra <[email protected]> wrote ---

Quoted 36 lines · Li Chen
Quoted 35 lines

+Peter, Dan, and Bjorn

(My apologies for the oversight)

---- On Wed, 05 Nov 2025 16:46:55 +0800 Li Chen <[email protected]> wrote ---

Quoted 30 lines

From: Li Chen <[email protected]>

Hello,

This patch series introduces a new GCC plugin called cleanup_plugin that warns developers about problematic patterns when using variables with __attribute__((cleanup(...))). The plugin addresses concerns documented in include/linux/cleanup.h regarding resource leaks and interdependency issues.

The cleanup attribute helpers (__free, DEFINE_FREE, etc.) are designed to automatically clean up resources when variables go out of scope, following LIFO (last in first out) ordering. However, certain patterns can lead to subtle bugs:

1. Uninitialized cleanup variables: Variables declared with cleanup attributes but not initialized can cause issues when cleanup functions are called on undefined values.

2. NULL-initialized cleanup variables: The "__free(...) = NULL" pattern at function top can cause interdependency problems, especially when combined with guards or multiple cleanup variables, as the cleanup may run in unexpected contexts.

The plugin detects both of these problematic patterns and provides clear warnings to developers, helping prevent incorrect cleanup ordering. Importantly, the plugin's warnings are not converted
to errors by -Werror, allowing builds to continue while still alerting developers to potential issues.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

The plugin is enabled by default as it provides valuable compile-time feedback without impacting build performance.

IIRC GCC also allow dumb stuff like gotos into the scope of a cleanup variable, where clang will fail the compile. Does this plugin also fix this?

I'm sorry, but I don't fully understand what you mean by "gotos into the scope of a cleanup variable". Could you please provide a sample to illustrate this issue? And I would try to fix it here if I can.

Regards,

Li​

author
#10 lore raw

RFC PATCH 1/2 gcc-plugins: add cleanup_plugin for uninitialized cleanup detection

In reply to Li Chen

From: Li Chen <[email protected]>

Add a GCC plugin to warn about uninitialized automatic variables with cleanup attributes. This helps catch this potential interdependency problem as documented in include/linux/cleanup.h.

The plugin detects uninitialized cleanup variables and warns developers without blocking builds (warnings are not converted to errors by -Werror).

---
 scripts/Makefile.gcc-plugins         |   1 +
 scripts/gcc-plugins/Kconfig          |   6 ++
 scripts/gcc-plugins/cleanup_plugin.c | 106 +++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 scripts/gcc-plugins/cleanup_plugin.c
scripts/Makefile.gcc-plugins +1 -0
index b0e1423b09c21..b948261c142e6 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
+gcc-plugin-$(CONFIG_GCC_PLUGIN_CLEANUP_ATTRIBUTE_WARN) += cleanup_plugin.so
 gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)	+= latent_entropy_plugin.so
 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY)		\
 		+= -DLATENT_ENTROPY_PLUGIN
scripts/gcc-plugins/Kconfig +6 -0
index 6b34ba19358d8..906d50eb5efa6 100644
@@ -36,4 +36,10 @@ config GCC_PLUGIN_LATENT_ENTROPY
 	   * https://grsecurity.net/
 	   * https://pax.grsecurity.net/
 
+config GCC_PLUGIN_CLEANUP_ATTRIBUTE_WARN
+	def_bool y
+	help
+	  Warn when local automatic variables annotated with
+	  __attribute__((cleanup(...))) are declared without an initializer.
+
 endif
scripts/gcc-plugins/cleanup_plugin.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.51.0
#11 lore raw

Re: [RFC PATCH 1/2] gcc-plugins: add cleanup_plugin for uninitialized cleanup detection

kernel test robot noticed the following build errors:

Hi Li,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on kees/for-next/hardening]
[also build test ERROR on kees/for-next/pstore kees/for-next/kspp linus/master v6.18-rc4 next-20251107] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Li-Chen/gcc-plugins-cleanup_plugin-detect-NULL-init/20251105-174800
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
patch link:    https://lore.kernel.org/r/20251105084733.3598704-6-me%40linux.beauty
patch subject: [RFC PATCH 1/2] gcc-plugins: add cleanup_plugin for uninitialized cleanup detection
config: s390-randconfig-001-20251107 (https://download.01.org/0day-ci/archive/20251107/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251107/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

scripts/gcc-plugins/cleanup_plugin.c: In function 'void warn_if_uninitialized(tree)':

>> scripts/gcc-plugins/cleanup_plugin.c:70:45: error: 'struct diagnostic_context' has no member named 'warning_as_error_requested_p'; did you mean 'warning_as_error_requested'?
      70 |         saved_warning_as_error = global_dc->warning_as_error_requested_p();
         |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                             warning_as_error_requested
>> scripts/gcc-plugins/cleanup_plugin.c:71:20: error: 'struct diagnostic_context' has no member named 'set_warning_as_error_requested'; did you mean 'warning_as_error_requested'?
      71 |         global_dc->set_warning_as_error_requested(false);
         |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                    warning_as_error_requested
   scripts/gcc-plugins/cleanup_plugin.c:77:20: error: 'struct diagnostic_context' has no member named 'set_warning_as_error_requested'; did you mean 'warning_as_error_requested'?
      77 |         global_dc->set_warning_as_error_requested(saved_warning_as_error);
         |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                    warning_as_error_requested

make[4]: *** [scripts/gcc-plugins/Makefile:54: scripts/gcc-plugins/cleanup_plugin.so] Error 1 shuffle=3970265060 make[4]: Target 'scripts/gcc-plugins/' not remade because of errors.
make[3]: *** [scripts/Makefile.build:556: scripts/gcc-plugins] Error 2 shuffle=3970265060 make[3]: Target 'scripts/' not remade because of errors.
make[2]: *** [Makefile:1263: scripts] Error 2 shuffle=3970265060
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=3970265060
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2 shuffle=3970265060
make: Target 'prepare' not remade because of errors.

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for OF_GPIO
Depends on [n]: GPIOLIB [=y] && OF [=y] && HAS_IOMEM [=n]
Selected by [m]:
- REGULATOR_RT5133 [=m] && REGULATOR [=y] && I2C [=m] && GPIOLIB [=y] && OF [=y]

vim +70 scripts/gcc-plugins/cleanup_plugin.c

    56	
    57	static void warn_if_uninitialized(tree var)
    58	{
    59		location_t loc;
    60		bool saved_warning_as_error;
    61	
    62		if (has_declaration_initializer(var))
    63			return;
    64	
    65		loc = DECL_SOURCE_LOCATION(var);
    66		if (loc == UNKNOWN_LOCATION)
    67			return;
    68	
    69		/* Temporarily disable treating warnings as errors for this specific warning */
  > 70		saved_warning_as_error = global_dc->warning_as_error_requested_p();
  > 71		global_dc->set_warning_as_error_requested(false);
    72		warning_at(
    73			loc, 0,
    74			"%qD declared with cleanup attribute is not initialized at declaration",
    75			var);
    76		/* Restore the original setting */
    77		global_dc->set_warning_as_error_requested(saved_warning_as_error);
    78	}
    79	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#12 lore raw

RFC PATCH 2/2 gcc-plugins: cleanup_plugin: detect NULL init

In reply to Li Chen

From: Li Chen <[email protected]>

The cleanup_plugin should warn about both uninitialized cleanup variables and those initialized to NULL, as documented in include/linux/cleanup.h. The "__free(...) = NULL" pattern at function top poses interdependency problems.

Also, plugin warnings should not be converted to errors by -Werror, as they are informational warnings meant to guide developers, not block builds.

---
 scripts/gcc-plugins/Kconfig          |   2 +-
 scripts/gcc-plugins/cleanup_plugin.c | 122 ++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 13 deletions(-)
scripts/gcc-plugins/Kconfig +1 -1
index 906d50eb5efa6..ae6f79c617149 100644
@@ -40,6 +40,6 @@ config GCC_PLUGIN_CLEANUP_ATTRIBUTE_WARN
 	def_bool y
 	help
 	  Warn when local automatic variables annotated with
-	  __attribute__((cleanup(...))) are declared without an initializer.
+	  __attribute__((cleanup(...))) are declared without an constructor.
 
 endif
scripts/gcc-plugins/cleanup_plugin.c +110 -12

155 lines not on this page · raw message

Signature · 1 line
2.51.0
author
#13 lore raw
In reply to Li Chen

My apologies, please disregard the dm-pcache portion of this series. This series will focus solely on gcc-plugin.

---- On Wed, 05 Nov 2025 16:46:51 +0800 Li Chen <[email protected]> wrote ---

Quoted 19 lines

From: Li Chen <[email protected]>

This three-patch series tidies dm-pcache’s build glue and tightens the metadata scan.

Patch 1 allow dm-pcache to be linked into vmlinux and avoids clashing with the sunrpc cache_flush() by using obj-$(CONFIG_DM_PCACHE) and renaming the helper across the tree.

Patch 2 drops a redundant recomputation of the metadata slot pointer while walking headers.

Patch 3 zero-allocates a temporary buffer so callers never see stale metadata, relies on __free(kvfree) for cleanup, and only copies back once a valid record is found.

Thanks for your review.

Li Chen (3):
dm-pcache: allow built-in build and rename flush helper
dm-pcache: reuse meta_addr in pcache_meta_find_latest
dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest()

Quoted 11 lines
 drivers/md/dm-pcache/Makefile          |  2 +-
 drivers/md/dm-pcache/cache.c           |  2 +-
 drivers/md/dm-pcache/cache.h           |  2 +-
 drivers/md/dm-pcache/cache_req.c       |  6 +++---
 drivers/md/dm-pcache/pcache_internal.h | 15 ++++++++++-----
 5 files changed, 16 insertions(+), 11 deletions(-)
Signature · 1 line
2.51.0

Regards,

Li​