linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: "Verma, Vishal L" <vishal.l.verma@intel.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"Busch, Keith" <keith.busch@intel.com>,
	"Weiny, Ira" <ira.weiny@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>
Subject: Re: [PATCH] libnvdimm, region: Use struct_size() in kzalloc()
Date: Wed, 28 Aug 2019 14:36:59 -0500	[thread overview]
Message-ID: <d940183a-c00d-3a96-37bb-9553583f160a@embeddedor.com> (raw)
In-Reply-To: <3e80b36c86942278ee66aebdd5ea2632f104083a.camel@intel.com>

Hi Vishal,

On 8/28/19 1:51 PM, Verma, Vishal L wrote:

[..]

> 
> Hi Gustavo,
> 
> The patch looks good to me, however it looks like it might've missed
> some instances where this replacement can be performed?
> 

struct_size() does not apply to those scenarios. See below...

> 
> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm.git/tree/drivers/nvdimm/region_devs.c#n1030

struct_size() only applies to structures of the following kind:

struct foo {
   int stuff;
   struct boo entry[];
};

and this scenario includes two different structures:

struct nd_region {

	...

        struct nd_mapping mapping[0];
};

struct nd_blk_region {

	...

        struct nd_region nd_region;
};

> [2]: https://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm.git/tree/drivers/nvdimm/region_devs.c#n96
> 

In this scenario struct_size() does not apply directly because of the following
logic before the call to devm_kzalloc():

 	size_t flush_data_size = sizeof(void *);
	
	[..]

        for (i = 0; i < nd_region->ndr_mappings; i++) {

		[..]

                /* at least one null hint slot per-dimm for the "no-hint" case */
                flush_data_size += sizeof(void *);
		
		[..]

                flush_data_size += nvdimm->num_flush * sizeof(void *);
        }

Thanks
--
Gustavo


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

  reply	other threads:[~2019-08-28 19:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10 21:06 [PATCH] libnvdimm, region: Use struct_size() in kzalloc() Gustavo A. R. Silva
2019-08-28 18:30 ` Gustavo A. R. Silva
2019-08-28 20:25   ` Kees Cook
2019-08-28 18:51 ` Verma, Vishal L
2019-08-28 19:36   ` Gustavo A. R. Silva [this message]
2019-08-28 20:24     ` Verma, Vishal L
2019-08-29 21:04       ` Dan Williams
  -- strict thread matches above, loose matches on Subject: below --
2019-02-21 15:23 [PATCH] libnvdimm, region: use " Gustavo A. R. Silva

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=d940183a-c00d-3a96-37bb-9553583f160a@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=keith.busch@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --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;
as well as URLs for NNTP newsgroup(s).