From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Bingbu Cao <bingbu.cao@intel.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
sakari.ailus@linux.intel.com, srinivas.kandagatla@linaro.org,
tfiga@chromium.org, bingbu.cao@linux.intel.com
Subject: Re: [PATCH] media: ov2740: add NVMEM interface to read customized OTP data
Date: Fri, 17 Jul 2020 20:06:10 +0900 [thread overview]
Message-ID: <20200717110610.GA3297952@google.com> (raw)
In-Reply-To: <1591954922-14006-1-git-send-email-bingbu.cao@intel.com>
On (20/06/12 17:42), Bingbu Cao wrote:
>
> +static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,
> + size_t count)
> +{
> + struct nvm_data *nvm = priv;
> +
> + memcpy(val, nvm->nvm_buffer + off, count);
> +
> + return 0;
> +}
> +
> +static int ov2740_register_nvmem(struct i2c_client *client)
> +{
> + struct nvm_data *nvm;
> + struct regmap_config regmap_config = { };
> + struct nvmem_config nvmem_config = { };
> + struct regmap *regmap;
> + struct device *dev = &client->dev;
> + int ret = 0;
> +
> + nvm = devm_kzalloc(dev, sizeof(*nvm), GFP_KERNEL);
> + if (!nvm)
> + return -ENOMEM;
> +
> + regmap_config.val_bits = 8;
> + regmap_config.reg_bits = 16;
> + regmap_config.disable_locking = true;
> + regmap = devm_regmap_init_i2c(client, ®map_config);
> + if (IS_ERR(regmap))
> + return PTR_ERR(regmap);
> +
> + nvm->regmap = regmap;
> +
> + nvmem_config.name = dev_name(dev);
> + nvmem_config.dev = dev;
> + nvmem_config.read_only = true;
> + nvmem_config.root_only = true;
> + nvmem_config.owner = THIS_MODULE;
> + nvmem_config.compat = true;
> + nvmem_config.base_dev = dev;
> + nvmem_config.reg_read = ov2740_nvmem_read;
> + nvmem_config.reg_write = NULL;
> + nvmem_config.priv = nvm;
> + nvmem_config.stride = 1;
> + nvmem_config.word_size = 1;
> + nvmem_config.size = CUSTOMER_USE_OTP_SIZE;
> +
> + nvm->nvmem = devm_nvmem_register(dev, &nvmem_config);
> + if (IS_ERR(nvm->nvmem))
> + return PTR_ERR(nvm->nvmem);
This registers the NVM device, but the underlying structure is not
completely initialized yet. For instance, the ->num_buffer, which
->reg_read() uses as buffer base address, is still NULL at this point.
I'd be more comfortable if we first fully setup/prepare everything and
only then register the device.
> +
> + nvm->nvm_buffer = devm_kzalloc(dev, CUSTOMER_USE_OTP_SIZE, GFP_KERNEL);
> + if (!nvm->nvm_buffer)
> + return -ENOMEM;
If this allocation fails, we return the error, which is handler as
dev_err() only, and keep everting as is. So any attempt of ->req_read()
will effectively do
memcpy(val, NULL + off, count);
> + ret = ov2740_load_otp_data(client, nvm);
> + if (ret)
> + dev_err(dev, "failed to load OTP data, ret %d\n", ret);
> +
> + return ret;
> +}
If this step fails, the NVM device is still registered and available
and we still can call ->req_read(). Is this correct? Do we need to
have an "error out" path there and unregister the NVM device?
> static int ov2740_probe(struct i2c_client *client)
> {
> struct ov2740 *ov2740;
> @@ -964,6 +1105,10 @@ static int ov2740_probe(struct i2c_client *client)
> goto probe_error_media_entity_cleanup;
> }
>
> + ret = ov2740_register_nvmem(client);
> + if (ret)
> + dev_err(&client->dev, "register nvmem failed, ret %d\n", ret);
> +
Either this better be a fatal error, or we need to have an error-out
rollback/cleanup in ov2740_register_nvmem().
> /*
> * Device is already turned on by i2c-core with ACPI domain PM.
> * Enable runtime PM and turn off the device.
-ss
prev parent reply other threads:[~2020-07-17 11:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 9:42 [PATCH] media: ov2740: add NVMEM interface to read customized OTP data Bingbu Cao
2020-06-15 9:29 ` Sakari Ailus
2020-06-15 9:46 ` Srinivas Kandagatla
2020-06-15 11:22 ` Sakari Ailus
2020-07-17 11:06 ` Sergey Senozhatsky [this message]
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=20200717110610.GA3297952@google.com \
--to=sergey.senozhatsky.work@gmail.com \
--cc=bingbu.cao@intel.com \
--cc=bingbu.cao@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=tfiga@chromium.org \
/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;
as well as URLs for NNTP newsgroup(s).