]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: change type of state in struct memory_block
authorIsrael Batista <linux@israelbatista.dev.br>
Wed, 29 Oct 2025 19:56:30 +0000 (19:56 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 17 Nov 2025 01:28:27 +0000 (17:28 -0800)
The state of a memory block should be restricted to values specified in
the documentation of the memory hotplug API.  However, since the state
field in the memory_block struct was defined as an unsigned long, this
restriction was not enforced at compile time.

With the introduction of the enum memory_block_state, it is now possible
to incorporate the desired semantics in the field declaration and enforce
these restrictions at compile time.

[akpm@linux-foundation.org: fix whitespace, per Randy]
Link: https://lkml.kernel.org/r/20251029195617.2210700-3-linux@israelbatista.dev.br
Signed-off-by: Israel Batista <linux@israelbatista.dev.br>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Omar Sandoval <osandov@osandov.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/base/memory.c
include/linux/memory.h

index 6d84a02cfa5dc4511e265e0c0d522f0431e56a78..3d17dd7749470aec61306f51538c9a03e4ed9e41 100644 (file)
@@ -198,7 +198,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
                break;
        default:
                WARN_ON(1);
-               return sysfs_emit(buf, "ERROR-UNKNOWN-%ld\n", mem->state);
+               return sysfs_emit(buf, "ERROR-UNKNOWN-%d\n", mem->state);
        }
 
        return sysfs_emit(buf, "%s\n", output);
index f4e358477c6a7e7045fbecc00f5f4432214037e8..ca20cbdd71f25c70a086896ed97a98eef69f01ea 100644 (file)
@@ -78,7 +78,7 @@ enum memory_block_state {
 
 struct memory_block {
        unsigned long start_section_nr;
-       unsigned long state;            /* serialized by the dev->lock */
+       enum memory_block_state state;  /* serialized by the dev->lock */
        int online_type;                /* for passing data to online routine */
        int nid;                        /* NID for this memory block */
        /*