aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/nvdimm/namespace_devs.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2016-09-21 21:16:21 -0400
committerDan Williams <dan.j.williams@intel.com>2016-10-05 23:24:18 -0400
commitf95b4bca9e7d29db284f9b175edf8deca1489def (patch)
treedfe75bf0ef883c9c84ececaf336cb16972c19449 /drivers/nvdimm/namespace_devs.c
parentae8219f186d8e98a3239afc6ea49bb46f2871d2f (diff)
libnvdimm, namespace: refactor uuid_show() into a namespace_to_uuid() helper
The ability to translate a generic struct device pointer into a namespace uuid is a useful utility as we go to unify the blk and pmem label scanning paths. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/nvdimm/namespace_devs.c')
-rw-r--r--drivers/nvdimm/namespace_devs.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 9f4188c78120..0e62f46755e7 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1032,22 +1032,27 @@ static ssize_t size_show(struct device *dev,
1032} 1032}
1033static DEVICE_ATTR(size, S_IRUGO, size_show, size_store); 1033static DEVICE_ATTR(size, S_IRUGO, size_show, size_store);
1034 1034
1035static ssize_t uuid_show(struct device *dev, 1035static u8 *namespace_to_uuid(struct device *dev)
1036 struct device_attribute *attr, char *buf)
1037{ 1036{
1038 u8 *uuid;
1039
1040 if (is_namespace_pmem(dev)) { 1037 if (is_namespace_pmem(dev)) {
1041 struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); 1038 struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev);
1042 1039
1043 uuid = nspm->uuid; 1040 return nspm->uuid;
1044 } else if (is_namespace_blk(dev)) { 1041 } else if (is_namespace_blk(dev)) {
1045 struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); 1042 struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev);
1046 1043
1047 uuid = nsblk->uuid; 1044 return nsblk->uuid;
1048 } else 1045 } else
1049 return -ENXIO; 1046 return ERR_PTR(-ENXIO);
1047}
1048
1049static ssize_t uuid_show(struct device *dev,
1050 struct device_attribute *attr, char *buf)
1051{
1052 u8 *uuid = namespace_to_uuid(dev);
1050 1053
1054 if (IS_ERR(uuid))
1055 return PTR_ERR(uuid);
1051 if (uuid) 1056 if (uuid)
1052 return sprintf(buf, "%pUb\n", uuid); 1057 return sprintf(buf, "%pUb\n", uuid);
1053 return sprintf(buf, "\n"); 1058 return sprintf(buf, "\n");