]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
spmi: use kzalloc_flex in main allocation
authorRosen Penev <rosenp@gmail.com>
Fri, 27 Mar 2026 02:41:43 +0000 (19:41 -0700)
committerStephen Boyd <sboyd@kernel.org>
Fri, 29 May 2026 01:40:46 +0000 (18:40 -0700)
Add a flexible array member to avoid indexing past the struct.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/spmi/spmi.c
include/linux/spmi.h

index e889b129f3ac39ec1fd24eced858d57e5eb0b4d7..57b7c0cb424076cb40fbbfe01cc3cffd46e7b0c9 100644 (file)
@@ -450,7 +450,7 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
        if (WARN_ON(!parent))
                return ERR_PTR(-EINVAL);
 
-       ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL);
+       ctrl = kzalloc_flex(*ctrl, priv, size);
        if (!ctrl)
                return ERR_PTR(-ENOMEM);
 
@@ -459,7 +459,7 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
        ctrl->dev.bus = &spmi_bus_type;
        ctrl->dev.parent = parent;
        ctrl->dev.of_node = parent->of_node;
-       spmi_controller_set_drvdata(ctrl, &ctrl[1]);
+       spmi_controller_set_drvdata(ctrl, ctrl->priv);
 
        id = ida_alloc(&ctrl_ida, GFP_KERNEL);
        if (id < 0) {
index 671ce1b3ee8e64da249c64319c4e40eb395a418c..4eb9564a7fb3f6ca3a040a6f7a4bde29b9e154c8 100644 (file)
@@ -76,6 +76,7 @@ void spmi_device_remove(struct spmi_device *sdev);
  * @cmd:       sends a non-data command sequence on the SPMI bus.
  * @read_cmd:  sends a register read command sequence on the SPMI bus.
  * @write_cmd: sends a register write command sequence on the SPMI bus.
+ * @priv:      array of private data.
  */
 struct spmi_controller {
        struct device           dev;
@@ -85,6 +86,7 @@ struct spmi_controller {
                            u8 sid, u16 addr, u8 *buf, size_t len);
        int     (*write_cmd)(struct spmi_controller *ctrl, u8 opcode,
                             u8 sid, u16 addr, const u8 *buf, size_t len);
+       u8      priv[];
 };
 
 static inline struct spmi_controller *to_spmi_controller(struct device *d)