linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] nvmem: patches for 5.8
@ 2020-05-11 14:50 Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 1/3] nvmem: imx-ocotp: Improve logic to save many code lines Srinivas Kandagatla
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Srinivas Kandagatla @ 2020-05-11 14:50 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla

Hi Greg,

Here are some nvmem patches for 5.8 which includes two trivial
code cleanups and one fix to drive write-protect pin for all usecases.

Can you please queue them up for 5.8.

Thanks,
srini

Anson Huang (1):
  nvmem: imx-ocotp: Improve logic to save many code lines

Michael Auchter (1):
  nvmem: ensure sysfs writes handle write-protect pin

Samuel Zou (1):
  nvmem: jz4780-efuse: Use PTR_ERR_OR_ZERO() to simplify code

 drivers/nvmem/core.c         | 52 ++++++++++++++++++------------------
 drivers/nvmem/imx-ocotp.c    |  9 ++-----
 drivers/nvmem/jz4780-efuse.c |  4 +--
 3 files changed, 29 insertions(+), 36 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] nvmem: imx-ocotp: Improve logic to save many code lines
  2020-05-11 14:50 [PATCH 0/3] nvmem: patches for 5.8 Srinivas Kandagatla
@ 2020-05-11 14:50 ` Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 2/3] nvmem: ensure sysfs writes handle write-protect pin Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 3/3] nvmem: jz4780-efuse: Use PTR_ERR_OR_ZERO() to simplify code Srinivas Kandagatla
  2 siblings, 0 replies; 4+ messages in thread
From: Srinivas Kandagatla @ 2020-05-11 14:50 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Anson Huang, Srinivas Kandagatla

From: Anson Huang <Anson.Huang@nxp.com>

Several logic improvements to save many code lines:

 - no need to use goto;
 - no need to assign return value;
 - combine different conditions of return value into one line.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/imx-ocotp.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 50bea2aadc1b..7a1ebd6fd08b 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -196,7 +196,6 @@ static int imx_ocotp_read(void *context, unsigned int offset,
 		if (*(buf - 1) == IMX_OCOTP_READ_LOCKED_VAL)
 			imx_ocotp_clr_err_if_set(priv);
 	}
-	ret = 0;
 
 read_end:
 	clk_disable_unprepare(priv->clk);
@@ -435,17 +434,13 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val,
 	       priv->base + IMX_OCOTP_ADDR_CTRL_SET);
 	ret = imx_ocotp_wait_for_busy(priv,
 				      priv->params->ctrl.bm_rel_shadows);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(priv->dev, "timeout during shadow register reload\n");
-		goto write_end;
-	}
 
 write_end:
 	clk_disable_unprepare(priv->clk);
 	mutex_unlock(&ocotp_mutex);
-	if (ret < 0)
-		return ret;
-	return bytes;
+	return ret < 0 ? ret : bytes;
 }
 
 static struct nvmem_config imx_ocotp_nvmem_config = {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] nvmem: ensure sysfs writes handle write-protect pin
  2020-05-11 14:50 [PATCH 0/3] nvmem: patches for 5.8 Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 1/3] nvmem: imx-ocotp: Improve logic to save many code lines Srinivas Kandagatla
@ 2020-05-11 14:50 ` Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 3/3] nvmem: jz4780-efuse: Use PTR_ERR_OR_ZERO() to simplify code Srinivas Kandagatla
  2 siblings, 0 replies; 4+ messages in thread
From: Srinivas Kandagatla @ 2020-05-11 14:50 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Michael Auchter, Srinivas Kandagatla

From: Michael Auchter <michael.auchter@ni.com>

Commit 2a127da461a9 ("nvmem: add support for the write-protect pin")
added support for handling write-protect pins to the nvmem core, and
Commit 1c89074bf850 ("eeprom: at24: remove the write-protect pin support")
retrofitted the at24 driver to use this support.

These changes broke write() on the nvmem sysfs attribute for eeproms
which utilize a write-protect pin, as the write callback invokes the
nvmem device's reg_write callback directly which no longer handles
changing the state of the write-protect pin.

Change the read and write callbacks for the sysfs attribute to invoke
nvmme_reg_read/nvmem_reg_write helpers which handle this, rather than
calling reg_read/reg_write directly.

Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
Signed-off-by: Michael Auchter <michael.auchter@ni.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c | 52 ++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ad6e55a75bdb..927eb5f6003f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -66,6 +66,30 @@ static LIST_HEAD(nvmem_lookup_list);
 
 static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
 
+static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
+			  void *val, size_t bytes)
+{
+	if (nvmem->reg_read)
+		return nvmem->reg_read(nvmem->priv, offset, val, bytes);
+
+	return -EINVAL;
+}
+
+static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
+			   void *val, size_t bytes)
+{
+	int ret;
+
+	if (nvmem->reg_write) {
+		gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
+		ret = nvmem->reg_write(nvmem->priv, offset, val, bytes);
+		gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
+		return ret;
+	}
+
+	return -EINVAL;
+}
+
 #ifdef CONFIG_NVMEM_SYSFS
 static const char * const nvmem_type_str[] = {
 	[NVMEM_TYPE_UNKNOWN] = "Unknown",
@@ -122,7 +146,7 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
 	if (!nvmem->reg_read)
 		return -EPERM;
 
-	rc = nvmem->reg_read(nvmem->priv, pos, buf, count);
+	rc = nvmem_reg_read(nvmem, pos, buf, count);
 
 	if (rc)
 		return rc;
@@ -159,7 +183,7 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 	if (!nvmem->reg_write)
 		return -EPERM;
 
-	rc = nvmem->reg_write(nvmem->priv, pos, buf, count);
+	rc = nvmem_reg_write(nvmem, pos, buf, count);
 
 	if (rc)
 		return rc;
@@ -287,30 +311,6 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem,
 
 #endif /* CONFIG_NVMEM_SYSFS */
 
-static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
-			  void *val, size_t bytes)
-{
-	if (nvmem->reg_read)
-		return nvmem->reg_read(nvmem->priv, offset, val, bytes);
-
-	return -EINVAL;
-}
-
-static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
-			   void *val, size_t bytes)
-{
-	int ret;
-
-	if (nvmem->reg_write) {
-		gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
-		ret = nvmem->reg_write(nvmem->priv, offset, val, bytes);
-		gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
-		return ret;
-	}
-
-	return -EINVAL;
-}
-
 static void nvmem_release(struct device *dev)
 {
 	struct nvmem_device *nvmem = to_nvmem_device(dev);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] nvmem: jz4780-efuse: Use PTR_ERR_OR_ZERO() to simplify code
  2020-05-11 14:50 [PATCH 0/3] nvmem: patches for 5.8 Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 1/3] nvmem: imx-ocotp: Improve logic to save many code lines Srinivas Kandagatla
  2020-05-11 14:50 ` [PATCH 2/3] nvmem: ensure sysfs writes handle write-protect pin Srinivas Kandagatla
@ 2020-05-11 14:50 ` Srinivas Kandagatla
  2 siblings, 0 replies; 4+ messages in thread
From: Srinivas Kandagatla @ 2020-05-11 14:50 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Samuel Zou, Hulk Robot, Srinivas Kandagatla

From: Samuel Zou <zou_wei@huawei.com>

Fixes coccicheck warning:

drivers/nvmem/jz4780-efuse.c:214:1-3: WARNING: PTR_ERR_OR_ZERO can be used

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Samuel Zou <zou_wei@huawei.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/jz4780-efuse.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvmem/jz4780-efuse.c b/drivers/nvmem/jz4780-efuse.c
index 512e1872ba36..0b01b840edd9 100644
--- a/drivers/nvmem/jz4780-efuse.c
+++ b/drivers/nvmem/jz4780-efuse.c
@@ -211,10 +211,8 @@ static int jz4780_efuse_probe(struct platform_device *pdev)
 	cfg.priv = efuse;
 
 	nvmem = devm_nvmem_register(dev, &cfg);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
 
-	return 0;
+	return PTR_ERR_OR_ZERO(nvmem);
 }
 
 static const struct of_device_id jz4780_efuse_match[] = {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-11 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 14:50 [PATCH 0/3] nvmem: patches for 5.8 Srinivas Kandagatla
2020-05-11 14:50 ` [PATCH 1/3] nvmem: imx-ocotp: Improve logic to save many code lines Srinivas Kandagatla
2020-05-11 14:50 ` [PATCH 2/3] nvmem: ensure sysfs writes handle write-protect pin Srinivas Kandagatla
2020-05-11 14:50 ` [PATCH 3/3] nvmem: jz4780-efuse: Use PTR_ERR_OR_ZERO() to simplify code Srinivas Kandagatla

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).