NVDIMM Device and Persistent Memory development
 help / color / mirror / Atom feed
From: Vaibhav Jain <vaibhav@linux.ibm.com>
To: "Verma, Vishal L" <vishal.l.verma@intel.com>,
	"nvdimm@lists.linux.dev" <nvdimm@lists.linux.dev>
Cc: "Williams, Dan J" <dan.j.williams@intel.com>,
	"aneesh.kumar@linux.ibm.com" <aneesh.kumar@linux.ibm.com>,
	"sbhat@linux.ibm.com" <sbhat@linux.ibm.com>,
	"Weiny, Ira" <ira.weiny@intel.com>
Subject: Re: [ndctl PATCH v4] libndctl: Update nvdimm flags in ndctl_cmd_submit()
Date: Wed, 23 Feb 2022 11:06:10 +0530	[thread overview]
Message-ID: <87tucqdu0l.fsf@vajain21.in.ibm.com> (raw)
In-Reply-To: <5e159e75b9ff3dfdaa46a7cbcb1c251786294f0b.camel@intel.com>

Thanks Vishal,

I have addressed your review comments in v5 of the patch here at
https://lore.kernel.org/nvdimm/20220222121519.1674117-1-vaibhav@linux.ibm.com

~ Vaibhav

"Verma, Vishal L" <vishal.l.verma@intel.com> writes:

> On Sat, 2022-02-19 at 18:09 +0530, Vaibhav Jain wrote:
>> 
>> > > @@ -1924,9 +1940,13 @@ static void *add_dimm(void *parent, int id, const char *dimm_base)
>> > >  	dimm->formats = formats;
>> > >  	/* Check if the given dimm supports nfit */
>> > >  	if (ndctl_bus_has_nfit(bus)) {
>> > > -		rc = populate_dimm_attributes(dimm, dimm_base, "nfit");
>> > > +		dimm->bus_prefix = strdup("nfit");
>> > > +		rc = dimm->bus_prefix ?
>> > > +			populate_dimm_attributes(dimm, dimm_base) : -ENOMEM
>> > >  	} else if (ndctl_bus_has_of_node(bus)) {
>> > > -		rc = add_papr_dimm(dimm, dimm_base);
>> > > +		dimm->bus_prefix = strdup("papr");
>> > > +		rc = dimm->bus_prefix ?
>> > > +			add_papr_dimm(dimm, dimm_base) : -ENOMEM;
>> > 
>> > For both of the above, it would be a bit more readable to just return
>> > ENOMEM directly after strdup() if it fails, and then carry on with
>> > add_<foo>_dimm().
>> > 
>> > 	dimm->bus_prefix = strdup("papr");
>> > 	if (!dimm->bus_prefix)
>> > 		return -ENOMEM;
>> > 	rc = add_papr_dimm(dimm, dimm_base);
>> > 	...
>> > 
>> Agree on the readability part but returning from there right away would
>> prevent the allocated 'struct ndctl_dimm *dimm' from being freed in the
>> error path. Also the function add_dimm() returns a 'void *' to 'struct
>> ndctl_dimm*' right now rather than an 'int'.
>> 
>> I propose updating the code as:
>> 
>> 	if (ndctl_bus_has_nfit(bus)) {
>> 		dimm->bus_prefix = strdup("nfit");
>> 		if (!dimm->bus_prefix) {
>> 			rc = -ENOMEM;
>> 			goto out;
>> 		}
>> 		rc =  populate_dimm_attributes(dimm, dimm_base);
>>          }
>
> Yes, that looks good, thanks!
>
>> 
>> > >  	}
>> > >  
>> > >  	if (rc == -ENODEV) {
>> > > @@ -3506,6 +3526,10 @@ NDCTL_EXPORT int ndctl_cmd_submit(struct ndctl_cmd *cmd)
>> > >  		rc = -ENXIO;
>> > >  	}
>> > >  	close(fd);
>> > > +
>> > > +	/* update dimm-flags if command submitted successfully */
>> > > +	if (!rc && cmd->dimm)
>> > > +		ndctl_refresh_dimm_flags(cmd->dimm);
>> > >   out:
>> > >  	cmd->status = rc;
>> > >  	return rc;
>> > > diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h
>> > > index 4d8622978790..e5c56295556d 100644
>> > > --- a/ndctl/lib/private.h
>> > > +++ b/ndctl/lib/private.h
>> > > @@ -75,6 +75,7 @@ struct ndctl_dimm {
>> > >  	char *unique_id;
>> > >  	char *dimm_path;
>> > >  	char *dimm_buf;
>> > > +	char *bus_prefix;
>> > >  	int health_eventfd;
>> > >  	int buf_len;
>> > >  	int id;
>> > > diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h
>> > > index 4d5cdbf6f619..b1bafd6d9788 100644
>> > > --- a/ndctl/libndctl.h
>> > > +++ b/ndctl/libndctl.h
>> > > @@ -223,6 +223,7 @@ int ndctl_dimm_is_active(struct ndctl_dimm *dimm);
>> > >  int ndctl_dimm_is_enabled(struct ndctl_dimm *dimm);
>> > >  int ndctl_dimm_disable(struct ndctl_dimm *dimm);
>> > >  int ndctl_dimm_enable(struct ndctl_dimm *dimm);
>> > > +void ndctl_refresh_dimm_flags(struct ndctl_dimm *dimm);
>> > >  
>> > >  struct ndctl_cmd;
>> > >  struct ndctl_cmd *ndctl_bus_cmd_new_ars_cap(struct ndctl_bus *bus,
>> > 
>> 
>

-- 
Cheers
~ Vaibhav

      reply	other threads:[~2022-02-23  5:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 20:58 [ndctl PATCH v4] libndctl: Update nvdimm flags in ndctl_cmd_submit() Vaibhav Jain
2022-02-19  0:25 ` Verma, Vishal L
2022-02-19 12:39   ` Vaibhav Jain
2022-02-22 15:56     ` Verma, Vishal L
2022-02-23  5:36       ` Vaibhav Jain [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tucqdu0l.fsf@vajain21.in.ibm.com \
    --to=vaibhav@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=sbhat@linux.ibm.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox