Skip to content

Commit af264e5

Browse files
tititiou36miquelraynal
authored andcommitted
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 <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/72597e9de2320a4109be2112e696399592edacd4.1729271136.git.christophe.jaillet@wanadoo.fr
1 parent 7b2e57c commit af264e5

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

drivers/mtd/nand/ecc-mxic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,21 +723,21 @@ static int mxic_ecc_finish_io_req_pipelined(struct nand_device *nand,
723723
return ret;
724724
}
725725

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 = {
727727
.init_ctx = mxic_ecc_init_ctx_external,
728728
.cleanup_ctx = mxic_ecc_cleanup_ctx,
729729
.prepare_io_req = mxic_ecc_prepare_io_req_external,
730730
.finish_io_req = mxic_ecc_finish_io_req_external,
731731
};
732732

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 = {
734734
.init_ctx = mxic_ecc_init_ctx_pipelined,
735735
.cleanup_ctx = mxic_ecc_cleanup_ctx,
736736
.prepare_io_req = mxic_ecc_prepare_io_req_pipelined,
737737
.finish_io_req = mxic_ecc_finish_io_req_pipelined,
738738
};
739739

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)
741741
{
742742
return &mxic_ecc_engine_pipelined_ops;
743743
}

drivers/mtd/nand/ecc-sw-bch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int nand_ecc_sw_bch_finish_io_req(struct nand_device *nand,
384384
return max_bitflips;
385385
}
386386

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 = {
388388
.init_ctx = nand_ecc_sw_bch_init_ctx,
389389
.cleanup_ctx = nand_ecc_sw_bch_cleanup_ctx,
390390
.prepare_io_req = nand_ecc_sw_bch_prepare_io_req,

drivers/mtd/nand/ecc-sw-hamming.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ static int nand_ecc_sw_hamming_finish_io_req(struct nand_device *nand,
638638
return max_bitflips;
639639
}
640640

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 = {
642642
.init_ctx = nand_ecc_sw_hamming_init_ctx,
643643
.cleanup_ctx = nand_ecc_sw_hamming_cleanup_ctx,
644644
.prepare_io_req = nand_ecc_sw_hamming_prepare_io_req,

drivers/mtd/nand/spi/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static int spinand_ondie_ecc_finish_io_req(struct nand_device *nand,
337337
return ret;
338338
}
339339

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 = {
341341
.init_ctx = spinand_ondie_ecc_init_ctx,
342342
.cleanup_ctx = spinand_ondie_ecc_cleanup_ctx,
343343
.prepare_io_req = spinand_ondie_ecc_prepare_io_req,

drivers/spi/spi-mtk-snfi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ static int mtk_snand_ecc_finish_io_req(struct nand_device *nand,
776776
return snf->ecc_stats.failed ? -EBADMSG : snf->ecc_stats.bitflips;
777777
}
778778

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 = {
780780
.init_ctx = mtk_snand_ecc_init_ctx,
781781
.cleanup_ctx = mtk_snand_ecc_cleanup_ctx,
782782
.prepare_io_req = mtk_snand_ecc_prepare_io_req,

drivers/spi/spi-mxic.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ static int mxic_spi_transfer_one(struct spi_controller *host,
640640
/* ECC wrapper */
641641
static int mxic_spi_mem_ecc_init_ctx(struct nand_device *nand)
642642
{
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();
644644
struct mxic_spi *mxic = nand->ecc.engine->priv;
645645

646646
mxic->ecc.use_pipelined_conf = true;
@@ -650,7 +650,7 @@ static int mxic_spi_mem_ecc_init_ctx(struct nand_device *nand)
650650

651651
static void mxic_spi_mem_ecc_cleanup_ctx(struct nand_device *nand)
652652
{
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();
654654
struct mxic_spi *mxic = nand->ecc.engine->priv;
655655

656656
mxic->ecc.use_pipelined_conf = false;
@@ -661,20 +661,20 @@ static void mxic_spi_mem_ecc_cleanup_ctx(struct nand_device *nand)
661661
static int mxic_spi_mem_ecc_prepare_io_req(struct nand_device *nand,
662662
struct nand_page_io_req *req)
663663
{
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();
665665

666666
return ops->prepare_io_req(nand, req);
667667
}
668668

669669
static int mxic_spi_mem_ecc_finish_io_req(struct nand_device *nand,
670670
struct nand_page_io_req *req)
671671
{
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();
673673

674674
return ops->finish_io_req(nand, req);
675675
}
676676

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 = {
678678
.init_ctx = mxic_spi_mem_ecc_init_ctx,
679679
.cleanup_ctx = mxic_spi_mem_ecc_cleanup_ctx,
680680
.prepare_io_req = mxic_spi_mem_ecc_prepare_io_req,

include/linux/mtd/nand-ecc-mxic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ struct mxic_ecc_engine;
1616

1717
#if IS_ENABLED(CONFIG_MTD_NAND_ECC_MXIC) && IS_REACHABLE(CONFIG_MTD_NAND_CORE)
1818

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);
2020
struct nand_ecc_engine *mxic_ecc_get_pipelined_engine(struct platform_device *spi_pdev);
2121
void mxic_ecc_put_pipelined_engine(struct nand_ecc_engine *eng);
2222
int mxic_ecc_process_data_pipelined(struct nand_ecc_engine *eng,
2323
unsigned int direction, dma_addr_t dirmap);
2424

2525
#else /* !CONFIG_MTD_NAND_ECC_MXIC */
2626

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)
2828
{
2929
return NULL;
3030
}

include/linux/mtd/nand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ enum nand_ecc_engine_integration {
293293
struct nand_ecc_engine {
294294
struct device *dev;
295295
struct list_head node;
296-
struct nand_ecc_engine_ops *ops;
296+
const struct nand_ecc_engine_ops *ops;
297297
enum nand_ecc_engine_integration integration;
298298
void *priv;
299299
};

0 commit comments

Comments
 (0)