mtd: spinand: Constify struct nand_ecc_engine_ops
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Fri, 18 Oct 2024 17:05:57 +0000 (19:05 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 21 Oct 2024 09:55:50 +0000 (11:55 +0200)
'struct nand_ecc_engine_ops' are not modified in these drivers.

Constifying this structure moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.

Update the prototype of mxic_ecc_get_pipelined_ops() accordingly.

On a x86_64, with allmodconfig, as an example:
Before:
======
   text    data     bss     dec     hex filename
  16709    1374      16   18099    46b3 drivers/mtd/nand/ecc-mxic.o

After:
=====
   text    data     bss     dec     hex filename
  16789    1294      16   18099    46b3 drivers/mtd/nand/ecc-mxic.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/72597e9de2320a4109be2112e696399592edacd4.1729271136.git.christophe.jaillet@wanadoo.fr
drivers/mtd/nand/ecc-mxic.c
drivers/mtd/nand/ecc-sw-bch.c
drivers/mtd/nand/ecc-sw-hamming.c
drivers/mtd/nand/spi/core.c
drivers/spi/spi-mtk-snfi.c
drivers/spi/spi-mxic.c
include/linux/mtd/nand-ecc-mxic.h
include/linux/mtd/nand.h

index 47e1094..86895e0 100644 (file)
@@ -723,21 +723,21 @@ static int mxic_ecc_finish_io_req_pipelined(struct nand_device *nand,
        return ret;
 }
 
-static struct nand_ecc_engine_ops mxic_ecc_engine_external_ops = {
+static const struct nand_ecc_engine_ops mxic_ecc_engine_external_ops = {
        .init_ctx = mxic_ecc_init_ctx_external,
        .cleanup_ctx = mxic_ecc_cleanup_ctx,
        .prepare_io_req = mxic_ecc_prepare_io_req_external,
        .finish_io_req = mxic_ecc_finish_io_req_external,
 };
 
-static struct nand_ecc_engine_ops mxic_ecc_engine_pipelined_ops = {
+static const struct nand_ecc_engine_ops mxic_ecc_engine_pipelined_ops = {
        .init_ctx = mxic_ecc_init_ctx_pipelined,
        .cleanup_ctx = mxic_ecc_cleanup_ctx,
        .prepare_io_req = mxic_ecc_prepare_io_req_pipelined,
        .finish_io_req = mxic_ecc_finish_io_req_pipelined,
 };
 
-struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void)
+const struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void)
 {
        return &mxic_ecc_engine_pipelined_ops;
 }
index 405552d..0d9310d 100644 (file)
@@ -384,7 +384,7 @@ static int nand_ecc_sw_bch_finish_io_req(struct nand_device *nand,
        return max_bitflips;
 }
 
-static struct nand_ecc_engine_ops nand_ecc_sw_bch_engine_ops = {
+static const struct nand_ecc_engine_ops nand_ecc_sw_bch_engine_ops = {
        .init_ctx = nand_ecc_sw_bch_init_ctx,
        .cleanup_ctx = nand_ecc_sw_bch_cleanup_ctx,
        .prepare_io_req = nand_ecc_sw_bch_prepare_io_req,
index 254db2e..f2d0eff 100644 (file)
@@ -638,7 +638,7 @@ static int nand_ecc_sw_hamming_finish_io_req(struct nand_device *nand,
        return max_bitflips;
 }
 
-static struct nand_ecc_engine_ops nand_ecc_sw_hamming_engine_ops = {
+static const struct nand_ecc_engine_ops nand_ecc_sw_hamming_engine_ops = {
        .init_ctx = nand_ecc_sw_hamming_init_ctx,
        .cleanup_ctx = nand_ecc_sw_hamming_cleanup_ctx,
        .prepare_io_req = nand_ecc_sw_hamming_prepare_io_req,
index 4d76f9f..b1df7f6 100644 (file)
@@ -337,7 +337,7 @@ static int spinand_ondie_ecc_finish_io_req(struct nand_device *nand,
        return ret;
 }
 
-static struct nand_ecc_engine_ops spinand_ondie_ecc_engine_ops = {
+static const struct nand_ecc_engine_ops spinand_ondie_ecc_engine_ops = {
        .init_ctx = spinand_ondie_ecc_init_ctx,
        .cleanup_ctx = spinand_ondie_ecc_cleanup_ctx,
        .prepare_io_req = spinand_ondie_ecc_prepare_io_req,
index ddd98dd..b2a135e 100644 (file)
@@ -776,7 +776,7 @@ static int mtk_snand_ecc_finish_io_req(struct nand_device *nand,
        return snf->ecc_stats.failed ? -EBADMSG : snf->ecc_stats.bitflips;
 }
 
-static struct nand_ecc_engine_ops mtk_snfi_ecc_engine_ops = {
+static const struct nand_ecc_engine_ops mtk_snfi_ecc_engine_ops = {
        .init_ctx = mtk_snand_ecc_init_ctx,
        .cleanup_ctx = mtk_snand_ecc_cleanup_ctx,
        .prepare_io_req = mtk_snand_ecc_prepare_io_req,
index 6156d69..7ef3ee5 100644 (file)
@@ -640,7 +640,7 @@ static int mxic_spi_transfer_one(struct spi_controller *host,
 /* ECC wrapper */
 static int mxic_spi_mem_ecc_init_ctx(struct nand_device *nand)
 {
-       struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
+       const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
        struct mxic_spi *mxic = nand->ecc.engine->priv;
 
        mxic->ecc.use_pipelined_conf = true;
@@ -650,7 +650,7 @@ static int mxic_spi_mem_ecc_init_ctx(struct nand_device *nand)
 
 static void mxic_spi_mem_ecc_cleanup_ctx(struct nand_device *nand)
 {
-       struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
+       const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
        struct mxic_spi *mxic = nand->ecc.engine->priv;
 
        mxic->ecc.use_pipelined_conf = false;
@@ -661,7 +661,7 @@ static void mxic_spi_mem_ecc_cleanup_ctx(struct nand_device *nand)
 static int mxic_spi_mem_ecc_prepare_io_req(struct nand_device *nand,
                                           struct nand_page_io_req *req)
 {
-       struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
+       const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
 
        return ops->prepare_io_req(nand, req);
 }
@@ -669,12 +669,12 @@ static int mxic_spi_mem_ecc_prepare_io_req(struct nand_device *nand,
 static int mxic_spi_mem_ecc_finish_io_req(struct nand_device *nand,
                                          struct nand_page_io_req *req)
 {
-       struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
+       const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops();
 
        return ops->finish_io_req(nand, req);
 }
 
-static struct nand_ecc_engine_ops mxic_spi_mem_ecc_engine_pipelined_ops = {
+static const struct nand_ecc_engine_ops mxic_spi_mem_ecc_engine_pipelined_ops = {
        .init_ctx = mxic_spi_mem_ecc_init_ctx,
        .cleanup_ctx = mxic_spi_mem_ecc_cleanup_ctx,
        .prepare_io_req = mxic_spi_mem_ecc_prepare_io_req,
index b125926..0da4b29 100644 (file)
@@ -16,7 +16,7 @@ struct mxic_ecc_engine;
 
 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_MXIC) && IS_REACHABLE(CONFIG_MTD_NAND_CORE)
 
-struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void);
+const struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void);
 struct nand_ecc_engine *mxic_ecc_get_pipelined_engine(struct platform_device *spi_pdev);
 void mxic_ecc_put_pipelined_engine(struct nand_ecc_engine *eng);
 int mxic_ecc_process_data_pipelined(struct nand_ecc_engine *eng,
@@ -24,7 +24,7 @@ int mxic_ecc_process_data_pipelined(struct nand_ecc_engine *eng,
 
 #else /* !CONFIG_MTD_NAND_ECC_MXIC */
 
-static inline struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void)
+static inline const struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void)
 {
        return NULL;
 }
index 1e42080..0e2f228 100644 (file)
@@ -293,7 +293,7 @@ enum nand_ecc_engine_integration {
 struct nand_ecc_engine {
        struct device *dev;
        struct list_head node;
-       struct nand_ecc_engine_ops *ops;
+       const struct nand_ecc_engine_ops *ops;
        enum nand_ecc_engine_integration integration;
        void *priv;
 };