Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: spinand: Constify struct nand_ecc_engine_ops

'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

authored by

Christophe JAILLET and committed by
Miquel Raynal
af264e59 7b2e57c2

+15 -15
+3 -3
drivers/mtd/nand/ecc-mxic.c
··· 723 723 return ret; 724 724 } 725 725 726 - static struct nand_ecc_engine_ops mxic_ecc_engine_external_ops = { 726 + static const struct nand_ecc_engine_ops mxic_ecc_engine_external_ops = { 727 727 .init_ctx = mxic_ecc_init_ctx_external, 728 728 .cleanup_ctx = mxic_ecc_cleanup_ctx, 729 729 .prepare_io_req = mxic_ecc_prepare_io_req_external, 730 730 .finish_io_req = mxic_ecc_finish_io_req_external, 731 731 }; 732 732 733 - static struct nand_ecc_engine_ops mxic_ecc_engine_pipelined_ops = { 733 + static const struct nand_ecc_engine_ops mxic_ecc_engine_pipelined_ops = { 734 734 .init_ctx = mxic_ecc_init_ctx_pipelined, 735 735 .cleanup_ctx = mxic_ecc_cleanup_ctx, 736 736 .prepare_io_req = mxic_ecc_prepare_io_req_pipelined, 737 737 .finish_io_req = mxic_ecc_finish_io_req_pipelined, 738 738 }; 739 739 740 - struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void) 740 + const struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void) 741 741 { 742 742 return &mxic_ecc_engine_pipelined_ops; 743 743 }
+1 -1
drivers/mtd/nand/ecc-sw-bch.c
··· 384 384 return max_bitflips; 385 385 } 386 386 387 - static struct nand_ecc_engine_ops nand_ecc_sw_bch_engine_ops = { 387 + static const struct nand_ecc_engine_ops nand_ecc_sw_bch_engine_ops = { 388 388 .init_ctx = nand_ecc_sw_bch_init_ctx, 389 389 .cleanup_ctx = nand_ecc_sw_bch_cleanup_ctx, 390 390 .prepare_io_req = nand_ecc_sw_bch_prepare_io_req,
+1 -1
drivers/mtd/nand/ecc-sw-hamming.c
··· 638 638 return max_bitflips; 639 639 } 640 640 641 - static struct nand_ecc_engine_ops nand_ecc_sw_hamming_engine_ops = { 641 + static const struct nand_ecc_engine_ops nand_ecc_sw_hamming_engine_ops = { 642 642 .init_ctx = nand_ecc_sw_hamming_init_ctx, 643 643 .cleanup_ctx = nand_ecc_sw_hamming_cleanup_ctx, 644 644 .prepare_io_req = nand_ecc_sw_hamming_prepare_io_req,
+1 -1
drivers/mtd/nand/spi/core.c
··· 337 337 return ret; 338 338 } 339 339 340 - static struct nand_ecc_engine_ops spinand_ondie_ecc_engine_ops = { 340 + static const struct nand_ecc_engine_ops spinand_ondie_ecc_engine_ops = { 341 341 .init_ctx = spinand_ondie_ecc_init_ctx, 342 342 .cleanup_ctx = spinand_ondie_ecc_cleanup_ctx, 343 343 .prepare_io_req = spinand_ondie_ecc_prepare_io_req,
+1 -1
drivers/spi/spi-mtk-snfi.c
··· 776 776 return snf->ecc_stats.failed ? -EBADMSG : snf->ecc_stats.bitflips; 777 777 } 778 778 779 - static struct nand_ecc_engine_ops mtk_snfi_ecc_engine_ops = { 779 + static const struct nand_ecc_engine_ops mtk_snfi_ecc_engine_ops = { 780 780 .init_ctx = mtk_snand_ecc_init_ctx, 781 781 .cleanup_ctx = mtk_snand_ecc_cleanup_ctx, 782 782 .prepare_io_req = mtk_snand_ecc_prepare_io_req,
+5 -5
drivers/spi/spi-mxic.c
··· 640 640 /* ECC wrapper */ 641 641 static int mxic_spi_mem_ecc_init_ctx(struct nand_device *nand) 642 642 { 643 - struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 643 + const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 644 644 struct mxic_spi *mxic = nand->ecc.engine->priv; 645 645 646 646 mxic->ecc.use_pipelined_conf = true; ··· 650 650 651 651 static void mxic_spi_mem_ecc_cleanup_ctx(struct nand_device *nand) 652 652 { 653 - struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 653 + const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 654 654 struct mxic_spi *mxic = nand->ecc.engine->priv; 655 655 656 656 mxic->ecc.use_pipelined_conf = false; ··· 661 661 static int mxic_spi_mem_ecc_prepare_io_req(struct nand_device *nand, 662 662 struct nand_page_io_req *req) 663 663 { 664 - struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 664 + const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 665 665 666 666 return ops->prepare_io_req(nand, req); 667 667 } ··· 669 669 static int mxic_spi_mem_ecc_finish_io_req(struct nand_device *nand, 670 670 struct nand_page_io_req *req) 671 671 { 672 - struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 672 + const struct nand_ecc_engine_ops *ops = mxic_ecc_get_pipelined_ops(); 673 673 674 674 return ops->finish_io_req(nand, req); 675 675 } 676 676 677 - static struct nand_ecc_engine_ops mxic_spi_mem_ecc_engine_pipelined_ops = { 677 + static const struct nand_ecc_engine_ops mxic_spi_mem_ecc_engine_pipelined_ops = { 678 678 .init_ctx = mxic_spi_mem_ecc_init_ctx, 679 679 .cleanup_ctx = mxic_spi_mem_ecc_cleanup_ctx, 680 680 .prepare_io_req = mxic_spi_mem_ecc_prepare_io_req,
+2 -2
include/linux/mtd/nand-ecc-mxic.h
··· 16 16 17 17 #if IS_ENABLED(CONFIG_MTD_NAND_ECC_MXIC) && IS_REACHABLE(CONFIG_MTD_NAND_CORE) 18 18 19 - struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void); 19 + const struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void); 20 20 struct nand_ecc_engine *mxic_ecc_get_pipelined_engine(struct platform_device *spi_pdev); 21 21 void mxic_ecc_put_pipelined_engine(struct nand_ecc_engine *eng); 22 22 int mxic_ecc_process_data_pipelined(struct nand_ecc_engine *eng, ··· 24 24 25 25 #else /* !CONFIG_MTD_NAND_ECC_MXIC */ 26 26 27 - static inline struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void) 27 + static inline const struct nand_ecc_engine_ops *mxic_ecc_get_pipelined_ops(void) 28 28 { 29 29 return NULL; 30 30 }
+1 -1
include/linux/mtd/nand.h
··· 293 293 struct nand_ecc_engine { 294 294 struct device *dev; 295 295 struct list_head node; 296 - struct nand_ecc_engine_ops *ops; 296 + const struct nand_ecc_engine_ops *ops; 297 297 enum nand_ecc_engine_integration integration; 298 298 void *priv; 299 299 };