[3/3] mei: vsc: Assign pinfo fields in variable declaration

Message ID 20240212094618.344921-4-sakari.ailus@linux.intel.com
State New
Headers
Series MEI VSC fixes and cleanups |

Commit Message

Sakari Ailus Feb. 12, 2024, 9:46 a.m. UTC
  Assign all possible fields of pinfo in variable declaration, instead of
just zeroing it there.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/misc/mei/vsc-tp.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
  

Comments

Sakari Ailus Feb. 12, 2024, 10:14 a.m. UTC | #1
Hi Greg,

Thanks for the review.

On Mon, Feb 12, 2024 at 11:02:04AM +0100, Greg Kroah-Hartman wrote:
> On Mon, Feb 12, 2024 at 11:46:18AM +0200, Sakari Ailus wrote:
> > Assign all possible fields of pinfo in variable declaration, instead of
> > just zeroing it there.
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  drivers/misc/mei/vsc-tp.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/misc/mei/vsc-tp.c b/drivers/misc/mei/vsc-tp.c
> > index 200af14490d7..1eda2860f63b 100644
> > --- a/drivers/misc/mei/vsc-tp.c
> > +++ b/drivers/misc/mei/vsc-tp.c
> > @@ -447,11 +447,16 @@ static int vsc_tp_match_any(struct acpi_device *adev, void *data)
> >  
> >  static int vsc_tp_probe(struct spi_device *spi)
> >  {
> > -	struct platform_device_info pinfo = { 0 };
> > +	struct vsc_tp *tp;
> > +	struct platform_device_info pinfo = {
> > +		.name = "intel_vsc",
> > +		.data = &tp,
> > +		.size_data = sizeof(tp),
> > +		.id = PLATFORM_DEVID_NONE,
> > +	};
> 
> But now you have potential stack data in the structure for the fields
> that you aren't assigning here, right?  Is that acceptable, or will it
> leak somewhere?

Hmm. I'm not quite sure what you mean.

The patch changes where the fields are assigned but the variable is only
used when the assignment is done in any case, so this doesn't change
anything.

> 
> This is why we generally do not do this type of style.  So unless you
> are fixing an issue here, please don't do it.

The only caveat in initialising a struct is that the possible holes due to
ABI aren't initialised, which generally is a concern with UAPI or network
(i.e. not here, and the patch doesn't change that anyway).
  

Patch

diff --git a/drivers/misc/mei/vsc-tp.c b/drivers/misc/mei/vsc-tp.c
index 200af14490d7..1eda2860f63b 100644
--- a/drivers/misc/mei/vsc-tp.c
+++ b/drivers/misc/mei/vsc-tp.c
@@ -447,11 +447,16 @@  static int vsc_tp_match_any(struct acpi_device *adev, void *data)
 
 static int vsc_tp_probe(struct spi_device *spi)
 {
-	struct platform_device_info pinfo = { 0 };
+	struct vsc_tp *tp;
+	struct platform_device_info pinfo = {
+		.name = "intel_vsc",
+		.data = &tp,
+		.size_data = sizeof(tp),
+		.id = PLATFORM_DEVID_NONE,
+	};
 	struct device *dev = &spi->dev;
 	struct platform_device *pdev;
 	struct acpi_device *adev;
-	struct vsc_tp *tp;
 	int ret;
 
 	tp = devm_kzalloc(dev, sizeof(*tp), GFP_KERNEL);
@@ -508,13 +513,8 @@  static int vsc_tp_probe(struct spi_device *spi)
 		ret = -ENODEV;
 		goto err_destroy_lock;
 	}
-	pinfo.fwnode = acpi_fwnode_handle(adev);
-
-	pinfo.name = "intel_vsc";
-	pinfo.data = &tp;
-	pinfo.size_data = sizeof(tp);
-	pinfo.id = PLATFORM_DEVID_NONE;
 
+	pinfo.fwnode = acpi_fwnode_handle(adev);
 	pdev = platform_device_register_full(&pinfo);
 	if (IS_ERR(pdev)) {
 		ret = PTR_ERR(pdev);