2024-04-14 14:08:37

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH v2 0/5] mmc: Constify struct sdhci_ops

Hi,

Changes in v2:
- Patch 5 - sdhci-s3c: add __maybe_unused, reported by kernel test
robot.
- Link to v1: https://lore.kernel.org/r/[email protected]

The local struct sdhci_ops can be made const for code safety.
No dependencies.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (5):
mmc: sdhci-esdhc-mcf: Constify struct sdhci_ops
mmc: sdhci-omap: Constify struct sdhci_ops
mmc: sdhci-sprd: Constify struct sdhci_ops
mmc: sdhci_am654: Constify struct sdhci_ops
mmc: sdhci-s3c: Choose sdhci_ops based on variant

drivers/mmc/host/sdhci-esdhc-mcf.c | 2 +-
drivers/mmc/host/sdhci-omap.c | 2 +-
drivers/mmc/host/sdhci-s3c.c | 31 +++++++++++++++++--------------
drivers/mmc/host/sdhci-sprd.c | 2 +-
drivers/mmc/host/sdhci_am654.c | 6 +++---
5 files changed, 23 insertions(+), 20 deletions(-)
---
base-commit: f67245b3062cdc225b37003085bdb2916e1670b6
change-id: 20240414-mmc-const-sdhci-ops-c85762883004

Best regards,
--
Krzysztof Kozlowski <[email protected]>



2024-04-14 14:08:51

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH v2 1/5] mmc: sdhci-esdhc-mcf: Constify struct sdhci_ops

The local struct sdhci_ops can be made const for code safety.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mmc/host/sdhci-esdhc-mcf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-mcf.c b/drivers/mmc/host/sdhci-esdhc-mcf.c
index c97363e2d86c..3ad87322f6a5 100644
--- a/drivers/mmc/host/sdhci-esdhc-mcf.c
+++ b/drivers/mmc/host/sdhci-esdhc-mcf.c
@@ -335,7 +335,7 @@ static void esdhc_mcf_copy_to_bounce_buffer(struct sdhci_host *host,
data->blksz * data->blocks);
}

-static struct sdhci_ops sdhci_esdhc_ops = {
+static const struct sdhci_ops sdhci_esdhc_ops = {
.reset = esdhc_mcf_reset,
.set_clock = esdhc_mcf_pltfm_set_clock,
.get_max_clock = esdhc_mcf_pltfm_get_max_clock,

--
2.34.1


2024-04-14 14:09:06

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH v2 2/5] mmc: sdhci-omap: Constify struct sdhci_ops

The local struct sdhci_ops can be made const for code safety.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mmc/host/sdhci-omap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-omap.c b/drivers/mmc/host/sdhci-omap.c
index 94076b095571..5841a9afeb9f 100644
--- a/drivers/mmc/host/sdhci-omap.c
+++ b/drivers/mmc/host/sdhci-omap.c
@@ -925,7 +925,7 @@ static void sdhci_omap_set_timeout(struct sdhci_host *host,
__sdhci_set_timeout(host, cmd);
}

-static struct sdhci_ops sdhci_omap_ops = {
+static const struct sdhci_ops sdhci_omap_ops = {
.set_clock = sdhci_omap_set_clock,
.set_power = sdhci_omap_set_power,
.enable_dma = sdhci_omap_enable_dma,

--
2.34.1


2024-04-14 14:09:30

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH v2 3/5] mmc: sdhci-sprd: Constify struct sdhci_ops

The local struct sdhci_ops can be made const for code safety.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mmc/host/sdhci-sprd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
index 685b1c648901..8776f4287119 100644
--- a/drivers/mmc/host/sdhci-sprd.c
+++ b/drivers/mmc/host/sdhci-sprd.c
@@ -439,7 +439,7 @@ static void sdhci_sprd_set_power(struct sdhci_host *host, unsigned char mode,
}
}

-static struct sdhci_ops sdhci_sprd_ops = {
+static const struct sdhci_ops sdhci_sprd_ops = {
.read_l = sdhci_sprd_readl,
.write_l = sdhci_sprd_writel,
.write_w = sdhci_sprd_writew,

--
2.34.1


2024-04-14 14:09:35

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH v2 4/5] mmc: sdhci_am654: Constify struct sdhci_ops

The local struct sdhci_ops can be made const for code safety.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mmc/host/sdhci_am654.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
index ba36123e4ccc..17ad32cfc0c3 100644
--- a/drivers/mmc/host/sdhci_am654.c
+++ b/drivers/mmc/host/sdhci_am654.c
@@ -543,7 +543,7 @@ static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
return 0;
}

-static struct sdhci_ops sdhci_am654_ops = {
+static const struct sdhci_ops sdhci_am654_ops = {
.platform_execute_tuning = sdhci_am654_platform_execute_tuning,
.get_max_clock = sdhci_pltfm_clk_get_max_clock,
.get_timeout_clock = sdhci_pltfm_clk_get_max_clock,
@@ -573,7 +573,7 @@ static const struct sdhci_am654_driver_data sdhci_am654_drvdata = {
.flags = IOMUX_PRESENT | FREQSEL_2_BIT | STRBSEL_4_BIT | DLL_PRESENT,
};

-static struct sdhci_ops sdhci_j721e_8bit_ops = {
+static const struct sdhci_ops sdhci_j721e_8bit_ops = {
.platform_execute_tuning = sdhci_am654_platform_execute_tuning,
.get_max_clock = sdhci_pltfm_clk_get_max_clock,
.get_timeout_clock = sdhci_pltfm_clk_get_max_clock,
@@ -597,7 +597,7 @@ static const struct sdhci_am654_driver_data sdhci_j721e_8bit_drvdata = {
.flags = DLL_PRESENT | DLL_CALIB,
};

-static struct sdhci_ops sdhci_j721e_4bit_ops = {
+static const struct sdhci_ops sdhci_j721e_4bit_ops = {
.platform_execute_tuning = sdhci_am654_platform_execute_tuning,
.get_max_clock = sdhci_pltfm_clk_get_max_clock,
.get_timeout_clock = sdhci_pltfm_clk_get_max_clock,

--
2.34.1


2024-04-14 14:10:11

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH v2 5/5] mmc: sdhci-s3c: Choose sdhci_ops based on variant

The difference between old S3C64xx and newer Exynos4 SDHCI controller
variants is in clock handling (the "no_divider" field in drvdata).
Choose the proper sdhci_ops based on the variant instead of patching
ops in probe, if Exynos4 is used.

This allows making struct sdhci_ops const for code safety and probably
opens further options in the future, as the dynamic pointer ops table is
not anymore that dynamic.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/mmc/host/sdhci-s3c.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 6493b0edba34..a71d56c7031f 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -130,14 +130,16 @@ struct sdhci_s3c {
* struct sdhci_s3c_drv_data - S3C SDHCI platform specific driver data
* @sdhci_quirks: sdhci host specific quirks.
* @no_divider: no or non-standard internal clock divider.
+ * @ops: sdhci_ops to use for this variant
*
* Specifies platform specific configuration of sdhci controller.
* Note: A structure for driver specific platform data is used for future
* expansion of its usage.
*/
struct sdhci_s3c_drv_data {
- unsigned int sdhci_quirks;
- bool no_divider;
+ unsigned int sdhci_quirks;
+ bool no_divider;
+ const struct sdhci_ops *ops;
};

static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
@@ -412,7 +414,7 @@ static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
}

-static struct sdhci_ops sdhci_s3c_ops = {
+static const struct sdhci_ops sdhci_s3c_ops_s3c6410 = {
.get_max_clock = sdhci_s3c_get_max_clk,
.set_clock = sdhci_s3c_set_clock,
.get_min_clock = sdhci_s3c_get_min_clock,
@@ -421,6 +423,15 @@ static struct sdhci_ops sdhci_s3c_ops = {
.set_uhs_signaling = sdhci_set_uhs_signaling,
};

+static const struct sdhci_ops sdhci_s3c_ops_exynos4 __maybe_unused = {
+ .get_max_clock = sdhci_cmu_get_max_clock,
+ .set_clock = sdhci_cmu_set_clock,
+ .get_min_clock = sdhci_cmu_get_min_clock,
+ .set_bus_width = sdhci_set_bus_width,
+ .reset = sdhci_reset,
+ .set_uhs_signaling = sdhci_set_uhs_signaling,
+};
+
#ifdef CONFIG_OF
static int sdhci_s3c_parse_dt(struct device *dev,
struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
@@ -560,7 +571,7 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
pdata->cfg_gpio(pdev, pdata->max_width);

host->hw_name = "samsung-hsmmc";
- host->ops = &sdhci_s3c_ops;
+ host->ops = &sdhci_s3c_ops_s3c6410;
host->quirks = 0;
host->quirks2 = 0;
host->irq = irq;
@@ -570,6 +581,7 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
if (drv_data) {
host->quirks |= drv_data->sdhci_quirks;
+ host->ops = drv_data->ops;
sc->no_divider = drv_data->no_divider;
}

@@ -617,16 +629,6 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
/* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;

- /*
- * If controller does not have internal clock divider,
- * we can use overriding functions instead of default.
- */
- if (sc->no_divider) {
- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
- }
-
/* It supports additional host capabilities if needed */
if (pdata->host_caps)
host->mmc->caps |= pdata->host_caps;
@@ -758,6 +760,7 @@ MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids);
#ifdef CONFIG_OF
static const struct sdhci_s3c_drv_data exynos4_sdhci_drv_data = {
.no_divider = true,
+ .ops = &sdhci_s3c_ops_exynos4,
};

static const struct of_device_id sdhci_s3c_dt_match[] = {

--
2.34.1


2024-04-15 01:46:00

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH v2 3/5] mmc: sdhci-sprd: Constify struct sdhci_ops



On 2024/4/14 22:07, Krzysztof Kozlowski wrote:
> The local struct sdhci_ops can be made const for code safety.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>

LGTM. Thanks.
Reviewed-by: Baolin Wang <[email protected]>

> ---
> drivers/mmc/host/sdhci-sprd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/sdhci-sprd.c b/drivers/mmc/host/sdhci-sprd.c
> index 685b1c648901..8776f4287119 100644
> --- a/drivers/mmc/host/sdhci-sprd.c
> +++ b/drivers/mmc/host/sdhci-sprd.c
> @@ -439,7 +439,7 @@ static void sdhci_sprd_set_power(struct sdhci_host *host, unsigned char mode,
> }
> }
>
> -static struct sdhci_ops sdhci_sprd_ops = {
> +static const struct sdhci_ops sdhci_sprd_ops = {
> .read_l = sdhci_sprd_readl,
> .write_l = sdhci_sprd_writel,
> .write_w = sdhci_sprd_writew,
>

2024-04-15 06:07:46

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] mmc: Constify struct sdhci_ops

On 14/04/24 17:07, Krzysztof Kozlowski wrote:
> Hi,
>
> Changes in v2:
> - Patch 5 - sdhci-s3c: add __maybe_unused, reported by kernel test
> robot.
> - Link to v1: https://lore.kernel.org/r/[email protected]
>
> The local struct sdhci_ops can be made const for code safety.
> No dependencies.
>
> Best regards,
> Krzysztof
>
> ---
> Krzysztof Kozlowski (5):
> mmc: sdhci-esdhc-mcf: Constify struct sdhci_ops
> mmc: sdhci-omap: Constify struct sdhci_ops
> mmc: sdhci-sprd: Constify struct sdhci_ops
> mmc: sdhci_am654: Constify struct sdhci_ops
> mmc: sdhci-s3c: Choose sdhci_ops based on variant
>
> drivers/mmc/host/sdhci-esdhc-mcf.c | 2 +-
> drivers/mmc/host/sdhci-omap.c | 2 +-
> drivers/mmc/host/sdhci-s3c.c | 31 +++++++++++++++++--------------
> drivers/mmc/host/sdhci-sprd.c | 2 +-
> drivers/mmc/host/sdhci_am654.c | 6 +++---
> 5 files changed, 23 insertions(+), 20 deletions(-)
> ---
> base-commit: f67245b3062cdc225b37003085bdb2916e1670b6
> change-id: 20240414-mmc-const-sdhci-ops-c85762883004
>
> Best regards,

For all:

Acked-by: Adrian Hunter <[email protected]>


2024-04-25 16:22:41

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] mmc: Constify struct sdhci_ops

On Sun, 14 Apr 2024 at 16:07, Krzysztof Kozlowski <[email protected]> wrote:
>
> Hi,
>
> Changes in v2:
> - Patch 5 - sdhci-s3c: add __maybe_unused, reported by kernel test
> robot.
> - Link to v1: https://lore.kernel.org/r/[email protected]
>
> The local struct sdhci_ops can be made const for code safety.
> No dependencies.
>
> Best regards,
> Krzysztof
>
> ---
> Krzysztof Kozlowski (5):
> mmc: sdhci-esdhc-mcf: Constify struct sdhci_ops
> mmc: sdhci-omap: Constify struct sdhci_ops
> mmc: sdhci-sprd: Constify struct sdhci_ops
> mmc: sdhci_am654: Constify struct sdhci_ops
> mmc: sdhci-s3c: Choose sdhci_ops based on variant
>
> drivers/mmc/host/sdhci-esdhc-mcf.c | 2 +-
> drivers/mmc/host/sdhci-omap.c | 2 +-
> drivers/mmc/host/sdhci-s3c.c | 31 +++++++++++++++++--------------
> drivers/mmc/host/sdhci-sprd.c | 2 +-
> drivers/mmc/host/sdhci_am654.c | 6 +++---
> 5 files changed, 23 insertions(+), 20 deletions(-)
> ---

Applied for next, thanks!

Kind regards
Uffe