[PATCH 4/6] firmware: samsung: acpm: Make acpm_ops const and access via pointer

Peter Griffin peter.griffin at linaro.org
Fri May 8 14:27:54 PDT 2026


On Wed, 6 May 2026 at 12:39, Tudor Ambarus <tudor.ambarus at linaro.org> wrote:
>
> Replace the embedded `struct acpm_ops` inside `struct acpm_handle` with
> a pointer to a `const struct acpm_ops`.
>
> Previously, the operations structure was embedded directly within the
> handle and populated dynamically at runtime via `acpm_setup_ops()`.
> This resulted in mutable function pointers and unnecessary per-instance
> memory overhead.
>
> By defining `exynos_acpm_driver_ops` statically as a `const` structure,
> the function pointers are now safely housed in the read-only `.rodata`
> section. This improves security by preventing function pointer
> overwrites, saves memory, and slightly reduces initialization overhead
> in `acpm_probe()`.
>
> Consequently, update all consumer drivers (clk, mfd) to access the
> operations via the new pointer indirection (`->ops->`). Finally, fix
> the previously empty kernel-doc description for the ops member to
> reflect its new pointer nature.
>
> Signed-off-by: Tudor Ambarus <tudor.ambarus at linaro.org>
> ---

Reviewed-by: Peter Griffin <peter.griffin at linaro.org>

>  drivers/clk/samsung/clk-acpm.c                     |  8 ++---
>  drivers/firmware/samsung/exynos-acpm.c             | 36 ++++++++++------------
>  drivers/mfd/sec-acpm.c                             |  6 ++--
>  .../linux/firmware/samsung/exynos-acpm-protocol.h  |  4 +--
>  4 files changed, 25 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/clk/samsung/clk-acpm.c b/drivers/clk/samsung/clk-acpm.c
> index 93667777094c..953ca8d5720a 100644
> --- a/drivers/clk/samsung/clk-acpm.c
> +++ b/drivers/clk/samsung/clk-acpm.c
> @@ -68,8 +68,8 @@ static unsigned long acpm_clk_recalc_rate(struct clk_hw *hw,
>  {
>         struct acpm_clk *clk = to_acpm_clk(hw);
>
> -       return clk->handle->ops.dvfs.get_rate(clk->handle, clk->mbox_chan_id,
> -                                             clk->id);
> +       return clk->handle->ops->dvfs.get_rate(clk->handle, clk->mbox_chan_id,
> +                                              clk->id);
>  }
>
>  static int acpm_clk_determine_rate(struct clk_hw *hw,
> @@ -89,8 +89,8 @@ static int acpm_clk_set_rate(struct clk_hw *hw, unsigned long rate,
>  {
>         struct acpm_clk *clk = to_acpm_clk(hw);
>
> -       return clk->handle->ops.dvfs.set_rate(clk->handle, clk->mbox_chan_id,
> -                                             clk->id, rate);
> +       return clk->handle->ops->dvfs.set_rate(clk->handle, clk->mbox_chan_id,
> +                                              clk->id, rate);
>  }
>
>  static const struct clk_ops acpm_clk_ops = {
> diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c
> index da960d3e1145..1a0d98b55439 100644
> --- a/drivers/firmware/samsung/exynos-acpm.c
> +++ b/drivers/firmware/samsung/exynos-acpm.c
> @@ -670,30 +670,26 @@ static int acpm_channels_init(struct acpm_info *acpm)
>         return 0;
>  }
>
> -/**
> - * acpm_setup_ops() - setup the operations structures.
> - * @acpm:      pointer to the driver data.
> - */
> -static void acpm_setup_ops(struct acpm_info *acpm)
> -{
> -       struct acpm_dvfs_ops *dvfs_ops = &acpm->handle.ops.dvfs;
> -       struct acpm_pmic_ops *pmic_ops = &acpm->handle.ops.pmic;
> -
> -       dvfs_ops->set_rate = acpm_dvfs_set_rate;
> -       dvfs_ops->get_rate = acpm_dvfs_get_rate;
> -
> -       pmic_ops->read_reg = acpm_pmic_read_reg;
> -       pmic_ops->bulk_read = acpm_pmic_bulk_read;
> -       pmic_ops->write_reg = acpm_pmic_write_reg;
> -       pmic_ops->bulk_write = acpm_pmic_bulk_write;
> -       pmic_ops->update_reg = acpm_pmic_update_reg;
> -}
> -
>  static void acpm_clk_pdev_unregister(void *data)
>  {
>         platform_device_unregister(data);
>  }
>
> +static const struct acpm_ops exynos_acpm_driver_ops = {
> +       .dvfs = {
> +               .set_rate = acpm_dvfs_set_rate,
> +               .get_rate = acpm_dvfs_get_rate,
> +       },
> +
> +       .pmic = {
> +               .read_reg = acpm_pmic_read_reg,
> +               .bulk_read = acpm_pmic_bulk_read,
> +               .write_reg = acpm_pmic_write_reg,
> +               .bulk_write = acpm_pmic_bulk_write,
> +               .update_reg = acpm_pmic_update_reg,
> +       },
> +};
> +
>  static int acpm_probe(struct platform_device *pdev)
>  {
>         const struct acpm_match_data *match_data;
> @@ -734,7 +730,7 @@ static int acpm_probe(struct platform_device *pdev)
>         if (ret)
>                 return ret;
>
> -       acpm_setup_ops(acpm);
> +       acpm->handle.ops = &exynos_acpm_driver_ops;
>
>         platform_set_drvdata(pdev, acpm);
>
> diff --git a/drivers/mfd/sec-acpm.c b/drivers/mfd/sec-acpm.c
> index 9e15b260b8df..3397d13d3b7f 100644
> --- a/drivers/mfd/sec-acpm.c
> +++ b/drivers/mfd/sec-acpm.c
> @@ -391,7 +391,7 @@ static int sec_pmic_acpm_bus_write(void *context, const void *data,
>  {
>         struct sec_pmic_acpm_bus_context *ctx = context;
>         struct acpm_handle *acpm = ctx->shared->acpm;
> -       const struct acpm_pmic_ops *pmic_ops = &acpm->ops.pmic;
> +       const struct acpm_pmic_ops *pmic_ops = &acpm->ops->pmic;
>         size_t val_count = count - BITS_TO_BYTES(ACPM_ADDR_BITS);
>         const u8 *d = data;
>         const u8 *vals = &d[BITS_TO_BYTES(ACPM_ADDR_BITS)];
> @@ -411,7 +411,7 @@ static int sec_pmic_acpm_bus_read(void *context, const void *reg_buf, size_t reg
>  {
>         struct sec_pmic_acpm_bus_context *ctx = context;
>         struct acpm_handle *acpm = ctx->shared->acpm;
> -       const struct acpm_pmic_ops *pmic_ops = &acpm->ops.pmic;
> +       const struct acpm_pmic_ops *pmic_ops = &acpm->ops->pmic;
>         const u8 *r = reg_buf;
>         u8 reg;
>
> @@ -430,7 +430,7 @@ static int sec_pmic_acpm_bus_reg_update_bits(void *context, unsigned int reg, un
>  {
>         struct sec_pmic_acpm_bus_context *ctx = context;
>         struct acpm_handle *acpm = ctx->shared->acpm;
> -       const struct acpm_pmic_ops *pmic_ops = &acpm->ops.pmic;
> +       const struct acpm_pmic_ops *pmic_ops = &acpm->ops->pmic;
>
>         return pmic_ops->update_reg(acpm, ctx->shared->acpm_chan_id, ctx->type, reg & 0xff,
>                                     ctx->shared->speedy_channel, val, mask);
> diff --git a/include/linux/firmware/samsung/exynos-acpm-protocol.h b/include/linux/firmware/samsung/exynos-acpm-protocol.h
> index b206efa62be6..fbf1829b33db 100644
> --- a/include/linux/firmware/samsung/exynos-acpm-protocol.h
> +++ b/include/linux/firmware/samsung/exynos-acpm-protocol.h
> @@ -42,10 +42,10 @@ struct acpm_ops {
>
>  /**
>   * struct acpm_handle - Reference to an initialized protocol instance
> - * @ops:
> + * @ops:       pointer to the constant ACPM protocol operations.
>   */
>  struct acpm_handle {
> -       struct acpm_ops ops;
> +       const struct acpm_ops *ops;
>  };
>
>  struct device;
>
> --
> 2.54.0.545.g6539524ca2-goog
>



More information about the linux-arm-kernel mailing list