Skip to content

Commit d846711

Browse files
committed
mtd: rawnand: Let callers use the bare Hamming helpers
Before the introduction of the ECC framework infrastructure, many drivers used the ->calculate/correct() Hamming helpers directly. The point of this framework was to avoid this kind of hackish calls and use a proper and generic API but it is true that in certain cases, drivers still need to use these helpers in order to do ECC computations on behalf of their limited hardware. Right after the introduction of the ECC engine core introduction, it was spotted that it was not possible to use the shiny rawnand software ECC helpers so easily because an ECC engine object should have been allocated and initialized first. While this works well in most cases, for these drivers just leveraging the power of a single helper in conjunction with some pretty old and limited hardware, it did not fit. The idea back then was to declare intermediate helpers which would make use of the exported software ECC engine bare functions while keeping the rawnand layer compatibility. As there was already functions with the rawnand_sw_hamming_ prefix it was decided to declare new local helpers for this purpose in each driver needing one. Besides being far from optimal, this design choice was blamed by Linus when he pulled the "fixes" pull request [1] so that is why now it is time to clean this mess up. Enhancing the implementation of the rawnand_ecc_sw_* helpers to support both cases, when the ECC object is instantiated and when it is not is a quite elegant way to solve this situation. This way, we can still use the existing and exported rawnand helpers while avoiding the need for each driver to declare its own helper. Following this change, most of the fixes sent in [2] can now be safely reverted. Only the fsmc fix will need to be kept because there is actually something specific to the driver to do in its ->correct() helper. [1] https://lore.kernel.org/lkml/CAHk-=wh_ZHF685Fni8V9is17mj=pFisUaZ_0=gq6nbK+ZcyQmg@mail.gmail.com/ [2] https://lore.kernel.org/linux-mtd/[email protected]/ Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 9be1446 commit d846711

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
364364
{
365365
struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv;
366366
unsigned int step_size = nand->ecc.ctx.conf.step_size;
367+
bool sm_order = engine_conf ? engine_conf->sm_order : false;
367368

368-
return ecc_sw_hamming_calculate(buf, step_size, code,
369-
engine_conf->sm_order);
369+
return ecc_sw_hamming_calculate(buf, step_size, code, sm_order);
370370
}
371371
EXPORT_SYMBOL(nand_ecc_sw_hamming_calculate);
372372

@@ -457,9 +457,10 @@ int nand_ecc_sw_hamming_correct(struct nand_device *nand, unsigned char *buf,
457457
{
458458
struct nand_ecc_sw_hamming_conf *engine_conf = nand->ecc.ctx.priv;
459459
unsigned int step_size = nand->ecc.ctx.conf.step_size;
460+
bool sm_order = engine_conf ? engine_conf->sm_order : false;
460461

461462
return ecc_sw_hamming_correct(buf, read_ecc, calc_ecc, step_size,
462-
engine_conf->sm_order);
463+
sm_order);
463464
}
464465
EXPORT_SYMBOL(nand_ecc_sw_hamming_correct);
465466

0 commit comments

Comments
 (0)