Skip to contentSkip to conversation

ACPI: NFIT: add helper to_nfit_mem() to take device to nfit_mem

PATCH Superseded Ben Dooks 4 participants 4 messages Jul 3, 2023 – Jul 5, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 1/1 ACPI: NFIT: add helper to_nfit_mem() to take device to nfit_mem

Add a quick helper to just do struct device to the struct nfit_mem field it should be referencing. This reduces the number of code lines in some of the followgn code as it removes the intermediate struct nvdimm.

---
 drivers/acpi/nfit/core.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/acpi/nfit/core.c +13 -14
index 0fcc247fdfac..9213b426b125 100644
@@ -1361,18 +1361,22 @@ static const struct attribute_group *acpi_nfit_attribute_groups[] = {
 	NULL,
 };
 
-static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
+static struct nfit_mem *to_nfit_mem(struct device *dev)
 {
 	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	return  nvdimm_provider_data(nvdimm);
+}
+
+static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
+{
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	return __to_nfit_memdev(nfit_mem);
 }
 
 static struct acpi_nfit_control_region *to_nfit_dcr(struct device *dev)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	return nfit_mem->dcr;
 }
@@ -1531,8 +1535,7 @@ static DEVICE_ATTR_RO(serial);
 static ssize_t family_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	if (nfit_mem->family < 0)
 		return -ENXIO;
@@ -1543,8 +1546,7 @@ static DEVICE_ATTR_RO(family);
 static ssize_t dsm_mask_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	if (nfit_mem->family < 0)
 		return -ENXIO;
@@ -1555,8 +1557,7 @@ static DEVICE_ATTR_RO(dsm_mask);
 static ssize_t flags_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 	u16 flags = __to_nfit_memdev(nfit_mem)->flags;
 
 	if (test_bit(NFIT_MEM_DIRTY, &nfit_mem->flags))
@@ -1576,8 +1577,7 @@ static DEVICE_ATTR_RO(flags);
 static ssize_t id_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	return sprintf(buf, "%s\n", nfit_mem->id);
 }
@@ -1586,8 +1586,7 @@ static DEVICE_ATTR_RO(id);
 static ssize_t dirty_shutdown_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	return sprintf(buf, "%d\n", nfit_mem->dirty_shutdown);
 }
Signature · 1 line
2.40.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Ben Dooks

Add a quick helper to just do struct device to the struct nfit_mem field it should be referencing. This reduces the number of code lines in some of the followgn code as it removes the intermediate

s/followgn/following/

Quoted 3 lines

struct nvdimm.

Quoted 85 lines
---
  drivers/acpi/nfit/core.c | 27 +++++++++++++--------------
  1 file changed, 13 insertions(+), 14 deletions(-)
drivers/acpi/nfit/core.c +13 -14
index 0fcc247fdfac..9213b426b125 100644
@@ -1361,18 +1361,22 @@ static const struct attribute_group *acpi_nfit_attribute_groups[] = {
  	NULL,
  };
 
-static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
+static struct nfit_mem *to_nfit_mem(struct device *dev)
  {
  	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	return  nvdimm_provider_data(nvdimm);
+}
+
+static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
+{
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
  	return __to_nfit_memdev(nfit_mem);
  }
 
  static struct acpi_nfit_control_region *to_nfit_dcr(struct device *dev)
  {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
  	return nfit_mem->dcr;
  }
@@ -1531,8 +1535,7 @@ static DEVICE_ATTR_RO(serial);
  static ssize_t family_show(struct device *dev,
  		struct device_attribute *attr, char *buf)
  {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
  	if (nfit_mem->family < 0)
  		return -ENXIO;
@@ -1543,8 +1546,7 @@ static DEVICE_ATTR_RO(family);
  static ssize_t dsm_mask_show(struct device *dev,
  		struct device_attribute *attr, char *buf)
  {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
  	if (nfit_mem->family < 0)
  		return -ENXIO;
@@ -1555,8 +1557,7 @@ static DEVICE_ATTR_RO(dsm_mask);
  static ssize_t flags_show(struct device *dev,
  		struct device_attribute *attr, char *buf)
  {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
  	u16 flags = __to_nfit_memdev(nfit_mem)->flags;
 
  	if (test_bit(NFIT_MEM_DIRTY, &nfit_mem->flags))
@@ -1576,8 +1577,7 @@ static DEVICE_ATTR_RO(flags);
  static ssize_t id_show(struct device *dev,
  		struct device_attribute *attr, char *buf)
  {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
  	return sprintf(buf, "%s\n", nfit_mem->id);
  }
@@ -1586,8 +1586,7 @@ static DEVICE_ATTR_RO(id);
  static ssize_t dirty_shutdown_show(struct device *dev,
  		struct device_attribute *attr, char *buf)
  {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
  	return sprintf(buf, "%d\n", nfit_mem->dirty_shutdown);
  }
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Ben Dooks
Quoted 10 lines · Ben Dooks

Add a quick helper to just do struct device to the struct nfit_mem field it should be referencing. This reduces the number of code lines in some of the followgn code as it removes the intermediate struct nvdimm.

---
 drivers/acpi/nfit/core.c | 27 +++++++++++++--------------

 1 file changed, 13 insertions(+), 14 deletions(-)

Modulo the typo Dave pointed out,

maintainer
#3 lore raw
In reply to Ben Dooks
Quoted 5 lines · Ben Dooks

Add a quick helper to just do struct device to the struct nfit_mem field it should be referencing. This reduces the number of code lines in some of the followgn code as it removes the intermediate struct nvdimm.

Hi Ben,
This a useful cleanup. Minor comments below.
Alison

Quoted 10 lines
---
 drivers/acpi/nfit/core.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/acpi/nfit/core.c +0 -0
index 0fcc247fdfac..9213b426b125 100644

drivers/acpi/nfit/core.c static const struct attribute_group *acpi_nfit_attribute_groups[] = { · line 1367

Quoted 9 lines
drivers/acpi/nfit/core.c +2 -2
@@ -1361,18 +1361,22 @@ static const struct attribute_group *acpi_nfit_attribute_groups[] = {
 	NULL,
 };
 
-static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
+static struct nfit_mem *to_nfit_mem(struct device *dev)
 {
 	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	return  nvdimm_provider_data(nvdimm);

I was going to say add a space before that return, but checkpatch beat me to it, with a warning. Please fix that up.
WARNING: Missing a blank line after declarations

drivers/acpi/nfit/core.c static const struct attribute_group *acpi_nfit_attribute_groups[] = { · line 1375

Quoted 8 lines
drivers/acpi/nfit/core.c +5 -0
+}
+
+static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
+{
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	return __to_nfit_memdev(nfit_mem);
 }

I was a bit puzzled why the diff looked awkward because when I applied the patch it fell nicely in order with the new helper function first. It all merges the same in the end but it's easier on reviewers eyes when well presented. Consider using diff.algorithm=patience (output shown below) when things scramble needlessly.

drivers/acpi/nfit/core.c +7 -2
@@ -1361,18 +1361,22 @@ static const struct attribute_group *acpi_nfit_attribute_groups[] = {
 	NULL,
 };
 
+static struct nfit_mem *to_nfit_mem(struct device *dev)
+{
+	struct nvdimm *nvdimm = to_nvdimm(dev);
+	return  nvdimm_provider_data(nvdimm);
+}
+
 static struct acpi_nfit_memory_map *to_nfit_memdev(struct device *dev)
 {
-	struct nvdimm *nvdimm = to_nvdimm(dev);
-	struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
+	struct nfit_mem *nfit_mem = to_nfit_mem(dev);
 
 	return __to_nfit_memdev(nfit_mem);
 }
 

snip

Quoted 1 line