linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bnvdimm/namsepace: Don't set claim_class on error
@ 2019-09-25 18:10 ira.weiny
  2019-09-25 18:36 ` Verma, Vishal L
  0 siblings, 1 reply; 5+ messages in thread
From: ira.weiny @ 2019-09-25 18:10 UTC (permalink / raw)
  To: Dan Williams, Vishal Verma; +Cc: kernel-janitors, linux-nvdimm

From: Ira Weiny <ira.weiny@intel.com>

Don't leave claim_class set to an invalid value if an error occurs in
btt_claim_class().

While we are here change the return type of __holder_class_store() to be
clear about the values it is returning.

This was found via code inspection.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 drivers/nvdimm/namespace_devs.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 5b22cecefc99..a020c166e1e7 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1510,16 +1510,19 @@ static ssize_t holder_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(holder);
 
-static ssize_t __holder_class_store(struct device *dev, const char *buf)
+static int __holder_class_store(struct device *dev, const char *buf)
 {
 	struct nd_namespace_common *ndns = to_ndns(dev);
 
 	if (dev->driver || ndns->claim)
 		return -EBUSY;
 
-	if (sysfs_streq(buf, "btt"))
-		ndns->claim_class = btt_claim_class(dev);
-	else if (sysfs_streq(buf, "pfn"))
+	if (sysfs_streq(buf, "btt")) {
+		int rc = btt_claim_class(dev);
+		if (rc < NVDIMM_CCLASS_NONE)
+			return rc;
+		ndns->claim_class = rc;
+	} else if (sysfs_streq(buf, "pfn"))
 		ndns->claim_class = NVDIMM_CCLASS_PFN;
 	else if (sysfs_streq(buf, "dax"))
 		ndns->claim_class = NVDIMM_CCLASS_DAX;
@@ -1528,10 +1531,6 @@ static ssize_t __holder_class_store(struct device *dev, const char *buf)
 	else
 		return -EINVAL;
 
-	/* btt_claim_class() could've returned an error */
-	if ((int)ndns->claim_class < 0)
-		return ndns->claim_class;
-
 	return 0;
 }
 
@@ -1539,7 +1538,7 @@ static ssize_t holder_class_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t len)
 {
 	struct nd_region *nd_region = to_nd_region(dev->parent);
-	ssize_t rc;
+	int rc;
 
 	nd_device_lock(dev);
 	nvdimm_bus_lock(dev);
@@ -1547,7 +1546,7 @@ static ssize_t holder_class_store(struct device *dev,
 	rc = __holder_class_store(dev, buf);
 	if (rc >= 0)
 		rc = nd_namespace_label_update(nd_region, dev);
-	dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc);
+	dev_dbg(dev, "%s(%d)\n", rc < 0 ? "fail " : "", rc);
 	nvdimm_bus_unlock(dev);
 	nd_device_unlock(dev);
 
-- 
2.20.1

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] bnvdimm/namsepace: Don't set claim_class on error
  2019-09-25 18:10 [PATCH] bnvdimm/namsepace: Don't set claim_class on error ira.weiny
@ 2019-09-25 18:36 ` Verma, Vishal L
  2019-09-25 18:49   ` Ira Weiny
  0 siblings, 1 reply; 5+ messages in thread
From: Verma, Vishal L @ 2019-09-25 18:36 UTC (permalink / raw)
  To: Williams, Dan J, Weiny, Ira; +Cc: kernel-janitors, linux-nvdimm

On Wed, 2019-09-25 at 11:10 -0700, ira.weiny@intel.com wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> Don't leave claim_class set to an invalid value if an error occurs in
> btt_claim_class().
> 
> While we are here change the return type of __holder_class_store() to be
> clear about the values it is returning.
> 
> This was found via code inspection.
> 
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> ---
>  drivers/nvdimm/namespace_devs.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)

One minor nit below, but otherwise it looks good to me:
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

> 
> diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
> index 5b22cecefc99..a020c166e1e7 100644
> --- a/drivers/nvdimm/namespace_devs.c
> +++ b/drivers/nvdimm/namespace_devs.c
> @@ -1510,16 +1510,19 @@ static ssize_t holder_show(struct device *dev,
>  }
>  static DEVICE_ATTR_RO(holder);
>  
> -static ssize_t __holder_class_store(struct device *dev, const char *buf)
> +static int __holder_class_store(struct device *dev, const char *buf)
>  {
>  	struct nd_namespace_common *ndns = to_ndns(dev);
>  
>  	if (dev->driver || ndns->claim)
>  		return -EBUSY;
>  
> -	if (sysfs_streq(buf, "btt"))
> -		ndns->claim_class = btt_claim_class(dev);
> -	else if (sysfs_streq(buf, "pfn"))
> +	if (sysfs_streq(buf, "btt")) {
> +		int rc = btt_claim_class(dev);

Need a blank line here separating variable declarations and code.

> +		if (rc < NVDIMM_CCLASS_NONE)
> +			return rc;
> +		ndns->claim_class = rc;
> +	} else if (sysfs_streq(buf, "pfn"))
>  		ndns->claim_class = NVDIMM_CCLASS_PFN;
>  	else if (sysfs_streq(buf, "dax"))
>  		ndns->claim_class = NVDIMM_CCLASS_DAX;
> @@ -1528,10 +1531,6 @@ static ssize_t __holder_class_store(struct device *dev, const char *buf)
>  	else
>  		return -EINVAL;
>  
> -	/* btt_claim_class() could've returned an error */
> -	if ((int)ndns->claim_class < 0)
> -		return ndns->claim_class;
> -
>  	return 0;
>  }
>  
> @@ -1539,7 +1538,7 @@ static ssize_t holder_class_store(struct device *dev,
>  		struct device_attribute *attr, const char *buf, size_t len)
>  {
>  	struct nd_region *nd_region = to_nd_region(dev->parent);
> -	ssize_t rc;
> +	int rc;
>  
>  	nd_device_lock(dev);
>  	nvdimm_bus_lock(dev);
> @@ -1547,7 +1546,7 @@ static ssize_t holder_class_store(struct device *dev,
>  	rc = __holder_class_store(dev, buf);
>  	if (rc >= 0)
>  		rc = nd_namespace_label_update(nd_region, dev);
> -	dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc);
> +	dev_dbg(dev, "%s(%d)\n", rc < 0 ? "fail " : "", rc);
>  	nvdimm_bus_unlock(dev);
>  	nd_device_unlock(dev);
>  

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] bnvdimm/namsepace: Don't set claim_class on error
  2019-09-25 18:36 ` Verma, Vishal L
@ 2019-09-25 18:49   ` Ira Weiny
  2019-09-26  7:08     ` Johannes Thumshirn
  0 siblings, 1 reply; 5+ messages in thread
From: Ira Weiny @ 2019-09-25 18:49 UTC (permalink / raw)
  To: Verma, Vishal L; +Cc: kernel-janitors, linux-nvdimm

> > 
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> > ---
> >  drivers/nvdimm/namespace_devs.c | 19 +++++++++----------
> >  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> One minor nit below, but otherwise it looks good to me:
> Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

Thanks...

> 
> > 
> > diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
> > index 5b22cecefc99..a020c166e1e7 100644
> > --- a/drivers/nvdimm/namespace_devs.c
> > +++ b/drivers/nvdimm/namespace_devs.c
> > @@ -1510,16 +1510,19 @@ static ssize_t holder_show(struct device *dev,
> >  }
> >  static DEVICE_ATTR_RO(holder);
> >  
> > -static ssize_t __holder_class_store(struct device *dev, const char *buf)
> > +static int __holder_class_store(struct device *dev, const char *buf)
> >  {
> >  	struct nd_namespace_common *ndns = to_ndns(dev);
> >  
> >  	if (dev->driver || ndns->claim)
> >  		return -EBUSY;
> >  
> > -	if (sysfs_streq(buf, "btt"))
> > -		ndns->claim_class = btt_claim_class(dev);
> > -	else if (sysfs_streq(buf, "pfn"))
> > +	if (sysfs_streq(buf, "btt")) {
> > +		int rc = btt_claim_class(dev);
> 
> Need a blank line here separating variable declarations and code.

<sigh> yea I know better...  ;-)

V2 sent...

Thanks,
Ira

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] bnvdimm/namsepace: Don't set claim_class on error
  2019-09-25 18:49   ` Ira Weiny
@ 2019-09-26  7:08     ` Johannes Thumshirn
  2019-09-26 16:05       ` Weiny, Ira
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Thumshirn @ 2019-09-26  7:08 UTC (permalink / raw)
  To: Ira Weiny, Verma, Vishal L; +Cc: kernel-janitors, linux-nvdimm

On 25/09/2019 20:49, Ira Weiny wrote:
>>>
>>> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
>>> ---
>>>  drivers/nvdimm/namespace_devs.c | 19 +++++++++----------
>>>  1 file changed, 9 insertions(+), 10 deletions(-)
>>
>> One minor nit below, but otherwise it looks good to me:
>> Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>

Another minor nit, the Subject says:
"bnvdimm/namsepace: Don't set claim_class on error"

a.k.a missing the 'li' part of libnvdimm

-- 
Johannes Thumshirn                            SUSE Labs Filesystems
jthumshirn@suse.de                                +49 911 74053 689
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5
90409 Nürnberg
Germany
(HRB 247165, AG München)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* RE: [PATCH] bnvdimm/namsepace: Don't set claim_class on error
  2019-09-26  7:08     ` Johannes Thumshirn
@ 2019-09-26 16:05       ` Weiny, Ira
  0 siblings, 0 replies; 5+ messages in thread
From: Weiny, Ira @ 2019-09-26 16:05 UTC (permalink / raw)
  To: Johannes Thumshirn, Verma, Vishal L; +Cc: kernel-janitors, linux-nvdimm

> On 25/09/2019 20:49, Ira Weiny wrote:
> >>>
> >>> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> >>> ---
> >>>  drivers/nvdimm/namespace_devs.c | 19 +++++++++----------
> >>>  1 file changed, 9 insertions(+), 10 deletions(-)
> >>
> >> One minor nit below, but otherwise it looks good to me:
> >> Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
> 
> Another minor nit, the Subject says:
> "bnvdimm/namsepace: Don't set claim_class on error"
> 
> a.k.a missing the 'li' part of libnvdimm

Yea...  I was just rushing.  V3 has this fix.

Thanks,
Ira

> 
> --
> Johannes Thumshirn                            SUSE Labs Filesystems
> jthumshirn@suse.de                                +49 911 74053 689
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5
> 90409 Nürnberg
> Germany
> (HRB 247165, AG München)
> Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2019-09-26 16:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 18:10 [PATCH] bnvdimm/namsepace: Don't set claim_class on error ira.weiny
2019-09-25 18:36 ` Verma, Vishal L
2019-09-25 18:49   ` Ira Weiny
2019-09-26  7:08     ` Johannes Thumshirn
2019-09-26 16:05       ` Weiny, Ira

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