Instead of always using a function pointer (and initializing it to our
default), just call the default function if the flash didn't set its own
one. That will make the call flow easier to follow.
Also mark the parameter as optional now.
Signed-off-by: Michael Walle <[email protected]>
---
drivers/mtd/spi-nor/core.c | 10 +++++-----
drivers/mtd/spi-nor/core.h | 8 ++++----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index f05ece6018dc..c8cc906cf771 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2532,11 +2532,12 @@ static int spi_nor_setup(struct spi_nor *nor,
{
int ret;
- if (nor->params->setup) {
+ if (nor->params->setup)
ret = nor->params->setup(nor, hwcaps);
- if (ret)
- return ret;
- }
+ else
+ ret = spi_nor_default_setup(nor, hwcaps);
+ if (ret)
+ return ret;
return spi_nor_set_addr_width(nor);
}
@@ -2786,7 +2787,6 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
params->quad_enable = spi_nor_sr2_bit1_quad_enable;
params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
- params->setup = spi_nor_default_setup;
params->otp.org = &info->otp_org;
/* Default to 16-bit Write Status (01h) Command */
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index c6578d3f598b..10f478547dc2 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -257,10 +257,10 @@ struct spi_nor_otp {
* @convert_addr: converts an absolute address into something the flash
* will understand. Particularly useful when pagesize is
* not a power-of-2.
- * @setup: configures the SPI NOR memory. Useful for SPI NOR
- * flashes that have peculiarities to the SPI NOR standard
- * e.g. different opcodes, specific address calculation,
- * page size, etc.
+ * @setup: (optional) configures the SPI NOR memory. Useful for
+ * SPI NOR flashes that have peculiarities to the SPI NOR
+ * standard e.g. different opcodes, specific address
+ * calculation, page size, etc.
* @locking_ops: SPI NOR locking methods.
*/
struct spi_nor_flash_parameter {
--
2.30.2
On 2/2/22 16:58, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> Instead of always using a function pointer (and initializing it to our
> default), just call the default function if the flash didn't set its own
> one. That will make the call flow easier to follow.
>
> Also mark the parameter as optional now.
what should be done in the future?
>
> Signed-off-by: Michael Walle <[email protected]>
Reviewed-by: Tudor Ambarus <[email protected]>
> ---
> drivers/mtd/spi-nor/core.c | 10 +++++-----
> drivers/mtd/spi-nor/core.h | 8 ++++----
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index f05ece6018dc..c8cc906cf771 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2532,11 +2532,12 @@ static int spi_nor_setup(struct spi_nor *nor,
> {
> int ret;
>
> - if (nor->params->setup) {
> + if (nor->params->setup)
> ret = nor->params->setup(nor, hwcaps);
> - if (ret)
> - return ret;
> - }
> + else
> + ret = spi_nor_default_setup(nor, hwcaps);
> + if (ret)
> + return ret;
>
> return spi_nor_set_addr_width(nor);
> }
> @@ -2786,7 +2787,6 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
>
> params->quad_enable = spi_nor_sr2_bit1_quad_enable;
> params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
> - params->setup = spi_nor_default_setup;
> params->otp.org = &info->otp_org;
>
> /* Default to 16-bit Write Status (01h) Command */
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index c6578d3f598b..10f478547dc2 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -257,10 +257,10 @@ struct spi_nor_otp {
> * @convert_addr: converts an absolute address into something the flash
> * will understand. Particularly useful when pagesize is
> * not a power-of-2.
> - * @setup: configures the SPI NOR memory. Useful for SPI NOR
> - * flashes that have peculiarities to the SPI NOR standard
> - * e.g. different opcodes, specific address calculation,
> - * page size, etc.
> + * @setup: (optional) configures the SPI NOR memory. Useful for
> + * SPI NOR flashes that have peculiarities to the SPI NOR
> + * standard e.g. different opcodes, specific address
> + * calculation, page size, etc.
> * @locking_ops: SPI NOR locking methods.
> */
> struct spi_nor_flash_parameter {
> --
> 2.30.2
>
Am 2022-02-10 04:00, schrieb [email protected]:
> On 2/2/22 16:58, Michael Walle wrote:
>> EXTERNAL EMAIL: Do not click links or open attachments unless you know
>> the content is safe
>>
>> Instead of always using a function pointer (and initializing it to our
>> default), just call the default function if the flash didn't set its
>> own
>> one. That will make the call flow easier to follow.
>>
>> Also mark the parameter as optional now.
>
> what should be done in the future?
What do you mean? IMHO the default path should be visible in the
function. Eg.
int spi_nor_bla(nor) {
if (nor->some_exceptional_cb)
return nor->some_exceptional_cb(nor);
return usual_cb(nor);
}
-michael
On 2/10/22 10:01, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> Am 2022-02-10 04:00, schrieb [email protected]:
>> On 2/2/22 16:58, Michael Walle wrote:
cut
>>> Also mark the parameter as optional now.
Oh, I misread, in my head I read "for now". That's why I asked what should
be done next :).
>>
>> what should be done in the future?
>
> What do you mean? IMHO the default path should be visible in the
> function. Eg.
>
> int spi_nor_bla(nor) {
> if (nor->some_exceptional_cb)
> return nor->some_exceptional_cb(nor);
>
> return usual_cb(nor);
> }
>
> -michael
On 02/02/22 03:58PM, Michael Walle wrote:
> Instead of always using a function pointer (and initializing it to our
> default), just call the default function if the flash didn't set its own
> one. That will make the call flow easier to follow.
>
> Also mark the parameter as optional now.
>
> Signed-off-by: Michael Walle <[email protected]>
Reviewed-by: Pratyush Yadav <[email protected]>
--
Regards,
Pratyush Yadav
Texas Instruments Inc.