From: Artem Bityutskiy <dedekind1@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-mtd@lists.infradead.org, kernel@pengutronix.de
Subject: Re: [PATCH] mtdchar: handle chips that have user otp but no factory otp
Date: Sat, 02 Mar 2013 17:41:24 +0200 [thread overview]
Message-ID: <1362238884.2745.28.camel@sauron> (raw)
In-Reply-To: <1361182768-31919-1-git-send-email-u.kleine-koenig@pengutronix.de>
On Mon, 2013-02-18 at 11:19 +0100, Uwe Kleine-König wrote:
> Before this patch mtd_read_fact_prot_reg was used to check availability
> for both MTD_OTP_FACTORY and MTD_OTP_USER access. This made accessing
> user otp for chips that don't have a factory otp area impossible. So use
> the right wrapper depending on the intended area to be accessed.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> I'm currently working on accessing the user otp area of MT29F2G nand
> flash that doesn't have a factory otp. Reading and writing are not ready
> yet, but this change is an obvious prerequisite.
>
> Best regards
> Uwe
>
> drivers/mtd/mtdchar.c | 30 +++++++++++++++++++-----------
> 1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
> index a6e7451..1f4034a 100644
> --- a/drivers/mtd/mtdchar.c
> +++ b/drivers/mtd/mtdchar.c
> @@ -371,26 +371,34 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
> struct mtd_info *mtd = mfi->mtd;
> size_t retlen;
> int ret = 0;
> -
> - /*
> - * Make a fake call to mtd_read_fact_prot_reg() to check if OTP
> - * operations are supported.
> - */
> - if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) == -EOPNOTSUPP)
> - return -EOPNOTSUPP;
> + int (*func)(struct mtd_info *, loff_t, size_t, size_t *, u_char *) =
> + NULL;
> + enum mtd_file_modes outmode = MTD_FILE_MODE_NORMAL;
In this particular case when we only have 2 modes I'd prefer to not
introduce a function pointer variable but directly call the function.
>
> switch (mode) {
> case MTD_OTP_FACTORY:
> - mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
> + outmode = MTD_FILE_MODE_OTP_FACTORY;
> + func = mtd_read_fact_prot_reg;
> break;
> case MTD_OTP_USER:
> - mfi->mode = MTD_FILE_MODE_OTP_USER;
> + outmode = MTD_FILE_MODE_OTP_USER;
> + func = mtd_read_user_prot_reg;
> break;
> - default:
> - ret = -EINVAL;
> case MTD_OTP_OFF:
> break;
> + default:
> + ret = -EINVAL;
Probably in this case you need to 'return -EINVAL', otherwise you modify
'mfi->mode' below which is an unexpected side-effect of '-EINVAL'.
> }
> +
> + /*
> + * Make a fake call to mtd_read_fact_prot_reg() or
> + * mtd_read_user_prot_reg() to check if OTP operations are supported.
> + */
> + if (func && func(mtd, -1, 0, &retlen, NULL) == -EOPNOTSUPP)
> + return -EOPNOTSUPP;
> +
> + mfi->mode = outmode;
> +
> return ret;
> }
> #else
--
Best Regards,
Artem Bityutskiy
next prev parent reply other threads:[~2013-03-02 15:40 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-18 10:19 [PATCH] mtdchar: handle chips that have user otp but no factory otp Uwe Kleine-König
2013-03-02 15:41 ` Artem Bityutskiy [this message]
2013-03-02 21:08 ` Uwe Kleine-König
2013-03-04 16:35 ` [PATCH v2] " Uwe Kleine-König
2013-03-04 16:47 ` [PATCH v2] mtd/nand: don't use {read,write}_buf for 8-bit transfers Uwe Kleine-König
2013-03-04 16:50 ` Uwe Kleine-König
2013-03-05 2:00 ` [PATCH v2] mtd/nand: don't use {read, write}_buf " Huang Shijie
2013-03-13 9:33 ` [PATCH v2] mtd/nand: don't use {read,write}_buf " Artem Bityutskiy
2013-11-26 21:03 ` Uwe Kleine-König
2013-11-27 6:59 ` Brian Norris
2013-03-13 10:26 ` Artem Bityutskiy
2013-04-05 12:13 ` David Woodhouse
2013-11-26 21:15 ` [PATCH v3] " Uwe Kleine-König
2013-11-27 7:35 ` Brian Norris
2013-11-29 12:20 ` Ezequiel Garcia
2013-11-30 6:04 ` Brian Norris
2013-11-30 11:19 ` Ezequiel Garcia
2013-11-30 16:35 ` Ezequiel Garcia
2013-11-30 16:51 ` Ezequiel Garcia
2013-11-30 19:01 ` Brian Norris
2013-11-30 21:06 ` Ezequiel Garcia
2013-12-02 19:40 ` Gupta, Pekon
2013-11-30 18:53 ` Brian Norris
2013-11-30 20:57 ` Ezequiel Garcia
2013-12-05 21:22 ` [PATCH v4] " Uwe Kleine-König
2013-12-17 5:48 ` Brian Norris
2013-12-17 21:46 ` Ezequiel Garcia
2013-12-19 7:39 ` Brian Norris
2014-01-14 8:12 ` Brian Norris
2014-01-14 8:29 ` Uwe Kleine-König
2013-03-06 8:47 ` [PATCH v2] mtdchar: handle chips that have user otp but no factory otp Artem Bityutskiy
2013-03-06 8:51 ` Uwe Kleine-König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1362238884.2745.28.camel@sauron \
--to=dedekind1@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-mtd@lists.infradead.org \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox