lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CY5PR11MB6366A3FD539462F8473D24DCED142@CY5PR11MB6366.namprd11.prod.outlook.com>
Date: Thu, 2 Jan 2025 13:20:44 +0000
From: "Usyskin, Alexander" <alexander.usyskin@...el.com>
To: Christophe JAILLET <christophe.jaillet@...adoo.fr>, Miquel Raynal
	<miquel.raynal@...tlin.com>, Richard Weinberger <richard@....at>, "Vignesh
 Raghavendra" <vigneshr@...com>, "De Marchi, Lucas"
	<lucas.demarchi@...el.com>, Thomas Hellström
	<thomas.hellstrom@...ux.intel.com>, "Vivi, Rodrigo" <rodrigo.vivi@...el.com>,
	Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>, Maxime Ripard
	<mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>, David Airlie
	<airlied@...il.com>, Simona Vetter <simona@...ll.ch>, Jani Nikula
	<jani.nikula@...ux.intel.com>, Joonas Lahtinen
	<joonas.lahtinen@...ux.intel.com>, Tvrtko Ursulin <tursulin@...ulin.net>,
	"Poosa, Karthik" <karthik.poosa@...el.com>
CC: "Abliyev, Reuven" <reuven.abliyev@...el.com>, "Weil, Oren jer"
	<oren.jer.weil@...el.com>, "linux-mtd@...ts.infradead.org"
	<linux-mtd@...ts.infradead.org>, "dri-devel@...ts.freedesktop.org"
	<dri-devel@...ts.freedesktop.org>, "intel-gfx@...ts.freedesktop.org"
	<intel-gfx@...ts.freedesktop.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, Tomas Winkler <tomasw@...il.com>
Subject: RE: [PATCH v4 02/11] mtd: add driver for intel graphics non-volatile
 memory device

> ...
> 
> > +struct intel_dg_nvm {
> > +	struct kref refcnt;
> > +	void __iomem *base;
> > +	size_t size;
> > +	unsigned int nregions;
> > +	struct {
> > +		const char *name;
> > +		u8 id;
> > +		u64 offset;
> > +		u64 size;
> > +	} regions[];
> 
> __counted_by(nregions)?
> 

Sure, will add

> > +};
> > +
> > +static void intel_dg_nvm_release(struct kref *kref)
> > +{
> > +	struct intel_dg_nvm *nvm = container_of(kref, struct intel_dg_nvm,
> refcnt);
> > +	int i;
> > +
> > +	pr_debug("freeing intel_dg nvm\n");
> > +	for (i = 0; i < nvm->nregions; i++)
> > +		kfree(nvm->regions[i].name);
> > +	kfree(nvm);
> > +}
> > +
> > +static int intel_dg_mtd_probe(struct auxiliary_device *aux_dev,
> > +			      const struct auxiliary_device_id *aux_dev_id)
> > +{
> > +	struct intel_dg_nvm_dev *invm =
> auxiliary_dev_to_intel_dg_nvm_dev(aux_dev);
> > +	struct device *device;
> > +	struct intel_dg_nvm *nvm;
> > +	unsigned int nregions;
> > +	unsigned int i, n;
> > +	size_t size;
> > +	char *name;
> > +	int ret;
> > +
> > +	device = &aux_dev->dev;
> > +
> > +	/* count available regions */
> > +	for (nregions = 0, i = 0; i < INTEL_DG_NVM_REGIONS; i++) {
> > +		if (invm->regions[i].name)
> > +			nregions++;
> > +	}
> > +
> > +	if (!nregions) {
> > +		dev_err(device, "no regions defined\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	size = sizeof(*nvm) + sizeof(nvm->regions[0]) * nregions;
> 
> struct_size()? (and maybe no need for size)
> 

Will do, thanks for suggestion

> > +	nvm = kzalloc(size, GFP_KERNEL);
> > +	if (!nvm)
> > +		return -ENOMEM;
> > +
> > +	kref_init(&nvm->refcnt);
> > +
> > +	nvm->nregions = nregions;
> > +	for (n = 0, i = 0; i < INTEL_DG_NVM_REGIONS; i++) {
> > +		if (!invm->regions[i].name)
> > +			continue;
> > +
> > +		name = kasprintf(GFP_KERNEL, "%s.%s",
> > +				 dev_name(&aux_dev->dev), invm-
> >regions[i].name);
> > +		if (!name)
> > +			continue;
> > +		nvm->regions[n].name = name;
> > +		nvm->regions[n].id = i;
> > +		n++;
> > +	}
> 
> Should we set the exact number of regions, should a kasprintf() fail?
> 	nvm->nregions = n;
> This would make __counted_by be more accurate in its check.
> 

Sounds good, will do

> > +
> > +	nvm->base = devm_ioremap_resource(device, &invm->bar);
> > +	if (IS_ERR(nvm->base)) {
> > +		dev_err(device, "mmio not mapped\n");
> > +		ret = PTR_ERR(nvm->base);
> > +		goto err;
> > +	}
> > +
> > +	dev_set_drvdata(&aux_dev->dev, nvm);
> > +
> > +	return 0;
> > +
> > +err:
> > +	kref_put(&nvm->refcnt, intel_dg_nvm_release);
> > +	return ret;
> > +}
> 
> ...
> 
> CJ

- - 
Thanks,
Sasha


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ