static int imx_scu_ocotp_read()

in imx-ocotp-scu.c [132:178]


static int imx_scu_ocotp_read(void *context, unsigned int offset,
			      void *val, size_t bytes)
{
	struct ocotp_priv *priv = context;
	u32 count, index, num_bytes;
	u32 *buf;
	void *p;
	int i, ret;

	index = offset;
	num_bytes = round_up(bytes, 4);
	count = num_bytes >> 2;

	if (count > (priv->data->nregs - index))
		count = priv->data->nregs - index;

	p = kzalloc(num_bytes, GFP_KERNEL);
	if (!p)
		return -ENOMEM;

	mutex_lock(&scu_ocotp_mutex);

	buf = p;

	for (i = index; i < (index + count); i++) {
		if (in_hole(context, i)) {
			*buf++ = 0;
			continue;
		}

		ret = imx_sc_misc_otp_fuse_read(priv->nvmem_ipc, i, buf);
		if (ret) {
			mutex_unlock(&scu_ocotp_mutex);
			kfree(p);
			return ret;
		}
		buf++;
	}

	memcpy(val, (u8 *)p, bytes);

	mutex_unlock(&scu_ocotp_mutex);

	kfree(p);

	return 0;
}