linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* sysfs output without newlines
@ 2020-08-29 18:23 Joe Perches
  2020-08-29 20:23 ` Denis Efremov
  2020-08-30  9:11 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 7+ messages in thread
From: Joe Perches @ 2020-08-29 18:23 UTC (permalink / raw)
  To: LKML, Denis Efremov, Greg Kroah-Hartman, Rafael J. Wysocki,
	Kees Cook, Gustavo A . R . Silva, Julia Lawall, Alex Dewar
  Cc: linux-wireless, Ulf Hansson, linux-usb, Madalin Bucur, linux-mmc,
	Arnd Bergmann, Kai Mäkisara, Pete Zaitcev, linux-i3c,
	Maxim Levitsky, linux-scsi, Michal Simek, linux-arm-kernel,
	Jakub Kicinski, York Sun, Stanislav Yakovlev,
	platform-driver-x86, Robert Richter, Alex Dubov,
	James E.J. Bottomley, Mark Brown, Borislav Petkov, Darren Hart,
	Mauro Carvalho Chehab, Tomas Winkler, Kalle Valo, linux-edac,
	Tony Luck, Martin K. Petersen, Boris Brezillon, netdev,
	Oliver Neukum, Douglas Miller, linux-spi, James Morse,
	David S. Miller, Andy Shevchenko

While doing an investigation for a possible treewide conversion of
sysfs output using sprintf/snprintf/scnprintf, I discovered
several instances of sysfs output without terminating newlines.

It seems likely all of these should have newline terminations
or have the \n\r termination changed to a single newline.

Anyone have any objection to patches adding newlines to these
in their original forms using sprintf/snprintf/scnprintf?

A few of these might be false positives as
	"%s", string
might already have string with a newline termination.

+++ drivers/edac/fsl_ddr_edac.c
+	return sysfs_emit(data, "0x%08x",
+	return sysfs_emit(data, "0x%08x",
+	return sysfs_emit(data, "0x%08x",
+++ drivers/edac/synopsys_edac.c
+	return sysfs_emit(data, "Data Poisoning: %s\n\r",
+		return sysfs_emit(buf, "1");
+		return sysfs_emit(buf, "0");
+		return sysfs_emit(buf, "1");
+		return sysfs_emit(buf, "0");
+		return sysfs_emit(buf, "0");
+		return sysfs_emit(buf, "1");
+		return sysfs_emit(buf, "0");
+	return sysfs_emit(buf, "%u", !!(data->status & mask));
+	return sysfs_emit(buf, "%u", data->tcrit2[index] * 1000);
+	return sysfs_emit(buf, "%d",
+	return sysfs_emit(buf, "%u", data->tcrit1[index] * 1000);
+	return sysfs_emit(buf, "%d",
+	return sysfs_emit(buf, "%d", data->toffset[index] * 500);
+++ drivers/i3c/master.c
+		return sysfs_emit(buf, "i3c:dcr%02Xmanuf%04X", devinfo.dcr,
+	return sysfs_emit(buf, "i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
+	return sysfs_emit(buf, "%s", dd->boardversion);
+	return sysfs_emit(buf, "%s", dd->serial);
+	return sysfs_emit(buf, "%s", (char *)ib_qib_version);
+	return sysfs_emit(buf, "%s", dd->boardversion);
+	return sysfs_emit(buf, "%s", dd->lbus_info);
+	return sysfs_emit(buf, "ipac:f%02Xv%08Xd%08X", idev->id_format,
+++ drivers/memstick/core/mspro_block.c
+	return sysfs_emit(buffer, "%s", (char *)s_attr->data);
+	return sysfs_emit(buf, "%s",
+	return sysfs_emit(buf, "%s",
+++ drivers/misc/mei/bus.c
+	return sysfs_emit(buf, "%s", cldev->name);
+	return sysfs_emit(buf, "%pUl", uuid);
+	return sysfs_emit(buf, "%02X", version);
+	return sysfs_emit(buf, "mei:%s:%pUl:%02X:",
+	return sysfs_emit(buf, "%d", maxconn);
+	return sysfs_emit(buf, "%d", fixed);
+	return sysfs_emit(buf, "%d", vt);
+	return sysfs_emit(buf, "%u", maxlen);
+	return sysfs_emit(buf, "%s", mei_dev_state_str(dev_state));
+++ drivers/misc/tifm_core.c
+	return sysfs_emit(buf, "%x", sock->type);
+			return sysfs_emit(buf, "%s",
+	return sysfs_emit(buf, "%d", dev->net_count);
+++ drivers/net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c
+		return sysfs_emit(buf, "%llx",
+		return sysfs_emit(buf, "none");
+++ drivers/net/ethernet/ibm/ehea/ehea_main.c
+	return sysfs_emit(buf, "%d", port->logical_port_id);
+++ drivers/net/wireless/intel/ipw2x00/ipw2200.c
+		return sysfs_emit(buf, "%s", priv->prom_net_dev->name);
+	return sysfs_emit(buf, "0x%04X",
+	return sysfs_emit(buf, "%d", il->retry_rate);
+	return sysfs_emit(buf, "%pOF", np);
+	return sysfs_emit(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
+++ drivers/platform/x86/dell-smbios-base.c
+		return sysfs_emit(buf, "%08x", da_tokens[i].location);
+		return sysfs_emit(buf, "%08x", da_tokens[i].value);
+	return sysfs_emit(buf, "%08x",
+++ drivers/scsi/st.c
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
+++ drivers/spi/spi-tle62x0.c
+	return sysfs_emit(buf, "%d", value);
+++ drivers/usb/class/cdc-acm.c
+	return sysfs_emit(buf, "%d", acm->ctrl_caps);
+	return sysfs_emit(buf, "%d", acm->country_rel_date);
+++ drivers/usb/class/usblp.c
+	return sysfs_emit(buf, "%s", usblp->device_id_string+2);
+	return sysfs_emit(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
+++ drivers/usb/misc/cytherm.c
+	return sysfs_emit(buf, "%i", cytherm->brightness);
+	return sysfs_emit(buf, "%c%i.%i", sign ? '-' : '+', temp >> 1,
+		return sysfs_emit(buf, "1");
+		return sysfs_emit(buf, "0");
+	return sysfs_emit(buf, "%d", retval);
+	return sysfs_emit(buf, "%d", retval);



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: sysfs output without newlines
  2020-08-29 18:23 sysfs output without newlines Joe Perches
@ 2020-08-29 20:23 ` Denis Efremov
  2020-08-29 20:33   ` Joe Perches
  2020-08-30  9:11 ` Greg Kroah-Hartman
  1 sibling, 1 reply; 7+ messages in thread
From: Denis Efremov @ 2020-08-29 20:23 UTC (permalink / raw)
  To: Joe Perches, LKML, Greg Kroah-Hartman, Rafael J. Wysocki,
	Kees Cook, Gustavo A . R . Silva, Julia Lawall, Alex Dewar
  Cc: linux-wireless, Ulf Hansson, linux-usb, Madalin Bucur, linux-mmc,
	Arnd Bergmann, Kai Mäkisara, Pete Zaitcev, linux-i3c,
	Maxim Levitsky, linux-scsi, Michal Simek, linux-arm-kernel,
	Jakub Kicinski, York Sun, Stanislav Yakovlev,
	platform-driver-x86, Robert Richter, Alex Dubov,
	James E.J. Bottomley, Mark Brown, Borislav Petkov, Darren Hart,
	Mauro Carvalho Chehab, Tomas Winkler, Kalle Valo, linux-edac,
	Tony Luck, Martin K. Petersen, Boris Brezillon, netdev,
	Oliver Neukum, Douglas Miller, linux-spi, James Morse,
	David S. Miller, Andy Shevchenko

Hi,

On 8/29/20 9:23 PM, Joe Perches wrote:
> While doing an investigation for a possible treewide conversion of
> sysfs output using sprintf/snprintf/scnprintf, I discovered
> several instances of sysfs output without terminating newlines.
> 
> It seems likely all of these should have newline terminations
> or have the \n\r termination changed to a single newline.

I think that it could break badly written scripts in rare cases.

> 
> Anyone have any objection to patches adding newlines to these
> in their original forms using sprintf/snprintf/scnprintf?

I'm not sure about existing cases, but I think it's a good
checkpatch.pl warning for new patches. It should be 
possible to check sysfs_emit() calls.

Thanks,
Denis

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: sysfs output without newlines
  2020-08-29 20:23 ` Denis Efremov
@ 2020-08-29 20:33   ` Joe Perches
  2020-09-01  9:07     ` David Laight
  0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2020-08-29 20:33 UTC (permalink / raw)
  To: Denis Efremov, LKML, Greg Kroah-Hartman, Rafael J. Wysocki,
	Kees Cook, Gustavo A . R . Silva, Julia Lawall, Alex Dewar
  Cc: linux-wireless, Ulf Hansson, linux-usb, Madalin Bucur, linux-mmc,
	Arnd Bergmann, Kai Mäkisara, Pete Zaitcev, linux-i3c,
	Maxim Levitsky, linux-scsi, Michal Simek, linux-arm-kernel,
	Jakub Kicinski, York Sun, Stanislav Yakovlev,
	platform-driver-x86, Robert Richter, Alex Dubov,
	James E.J. Bottomley, Mark Brown, Borislav Petkov, Darren Hart,
	Mauro Carvalho Chehab, Tomas Winkler, Kalle Valo, linux-edac,
	Tony Luck, Martin K. Petersen, Boris Brezillon, netdev,
	Oliver Neukum, Douglas Miller, linux-spi, James Morse,
	David S. Miller, Andy Shevchenko

On Sat, 2020-08-29 at 23:23 +0300, Denis Efremov wrote:
> Hi,
> 
> On 8/29/20 9:23 PM, Joe Perches wrote:
> > While doing an investigation for a possible treewide conversion of
> > sysfs output using sprintf/snprintf/scnprintf, I discovered
> > several instances of sysfs output without terminating newlines.
> > 
> > It seems likely all of these should have newline terminations
> > or have the \n\r termination changed to a single newline.
> 
> I think that it could break badly written scripts in rare cases.

Maybe.

Is sysfs output a nominally unchangeable api like seq_?
Dunno.  seq_ output is extended all the time.

I think whitespace isn't generally considered part of
sscanf type input content awareness.

> > Anyone have any objection to patches adding newlines to these
> > in their original forms using sprintf/snprintf/scnprintf?
> 
> I'm not sure about existing cases, but I think it's a good
> checkpatch.pl warning for new patches. It should be 
> possible to check sysfs_emit() calls.

Eventually, yes.

cheers, Joe


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: sysfs output without newlines
  2020-08-29 18:23 sysfs output without newlines Joe Perches
  2020-08-29 20:23 ` Denis Efremov
@ 2020-08-30  9:11 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-30  9:11 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-wireless, Ulf Hansson, linux-usb, Rafael J. Wysocki,
	linux-mmc, Kai Mäkisara, LKML, Pete Zaitcev, linux-i3c,
	Arnd Bergmann, linux-scsi, Madalin Bucur, Michal Simek,
	Alex Dewar, linux-arm-kernel, Jakub Kicinski, Tomas Winkler,
	linux-edac, Stanislav Yakovlev, platform-driver-x86,
	Robert Richter, Kees Cook, Alex Dubov, James E.J. Bottomley,
	Denis Efremov, Mark Brown, Borislav Petkov, Darren Hart,
	Mauro Carvalho Chehab, York Sun, Kalle Valo, Maxim Levitsky,
	Tony Luck, Martin K. Petersen, Boris Brezillon, netdev,
	Oliver Neukum, Douglas Miller, Gustavo A . R . Silva, linux-spi,
	Julia Lawall, James Morse, David S. Miller, Andy Shevchenko

On Sat, Aug 29, 2020 at 11:23:43AM -0700, Joe Perches wrote:
> While doing an investigation for a possible treewide conversion of
> sysfs output using sprintf/snprintf/scnprintf, I discovered
> several instances of sysfs output without terminating newlines.
> 
> It seems likely all of these should have newline terminations
> or have the \n\r termination changed to a single newline.
> 
> Anyone have any objection to patches adding newlines to these
> in their original forms using sprintf/snprintf/scnprintf?

No objection for me, patches for my subsystems will be gladly taken.

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: sysfs output without newlines
  2020-08-29 20:33   ` Joe Perches
@ 2020-09-01  9:07     ` David Laight
  2020-09-01 22:22       ` Pete Zaitcev
  0 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2020-09-01  9:07 UTC (permalink / raw)
  To: 'Joe Perches',
	Denis Efremov, LKML, Greg Kroah-Hartman, Rafael J. Wysocki,
	Kees Cook, Gustavo A . R . Silva, Julia Lawall, Alex Dewar
  Cc: linux-wireless, Ulf Hansson, linux-usb, Madalin Bucur, linux-mmc,
	Arnd Bergmann, Kai Mäkisara, Pete Zaitcev, linux-i3c,
	Maxim Levitsky, linux-scsi, Michal Simek, linux-arm-kernel,
	Jakub Kicinski, York Sun, Stanislav Yakovlev,
	platform-driver-x86, Robert Richter, Alex Dubov,
	James E.J. Bottomley, Mark Brown, Borislav Petkov, Darren Hart,
	Mauro Carvalho Chehab, Tomas Winkler, Kalle Valo, linux-edac,
	Tony Luck, Martin K. Petersen, Boris Brezillon, netdev,
	Oliver Neukum, Douglas Miller, linux-spi, James Morse,
	David S. Miller, Andy Shevchenko

From: Joe Perches
> Sent: 29 August 2020 21:34
...
> > On 8/29/20 9:23 PM, Joe Perches wrote:
> > > While doing an investigation for a possible treewide conversion of
> > > sysfs output using sprintf/snprintf/scnprintf, I discovered
> > > several instances of sysfs output without terminating newlines.
> > >
> > > It seems likely all of these should have newline terminations
> > > or have the \n\r termination changed to a single newline.
> >
> > I think that it could break badly written scripts in rare cases.
> 
> Maybe.
> 
> Is sysfs output a nominally unchangeable api like seq_?
> Dunno.  seq_ output is extended all the time.
> 
> I think whitespace isn't generally considered part of
> sscanf type input content awareness.

The shell will remove trailing '\n' (but not '\r') from:
	foo=$(cat bar)
So shell scripts are unlikely to be affected.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: sysfs output without newlines
  2020-09-01  9:07     ` David Laight
@ 2020-09-01 22:22       ` Pete Zaitcev
  2020-09-02  7:57         ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Pete Zaitcev @ 2020-09-01 22:22 UTC (permalink / raw)
  To: David Laight
  Cc: linux-wireless, Ulf Hansson, linux-usb, Rafael J. Wysocki,
	linux-mmc, Kai Mäkisara, Gustavo A . R . Silva, linux-i3c,
	Arnd Bergmann, linux-scsi, Madalin Bucur, Michal Simek,
	Alex Dewar, linux-arm-kernel, Jakub Kicinski, Tomas Winkler,
	linux-edac, Stanislav Yakovlev, platform-driver-x86,
	Robert Richter, Kees Cook, Alex Dubov, James E.J. Bottomley,
	Denis Efremov, Mark Brown, Borislav Petkov, Darren Hart,
	Mauro Carvalho Chehab, York Sun, Kalle Valo, Maxim Levitsky,
	Tony Luck, Martin K. Petersen, Boris Brezillon,
	Greg Kroah-Hartman, Oliver Neukum, Douglas Miller, LKML,
	linux-spi, Julia Lawall, James Morse, netdev,
	'Joe Perches',
	David S. Miller, Andy Shevchenko

On Tue, 1 Sep 2020 09:07:42 +0000
David Laight <David.Laight@ACULAB.COM> wrote:

> The shell will remove trailing '\n' (but not '\r') from:
> 	foo=$(cat bar)
> So shell scripts are unlikely to be affected.

Surprisingly enough, Python is okay with this:

    with open("/proc/sys/net/ipv4/ip_forward",'r') as fp:
        print(int(fp.read()))

Nonetheless, I would rather no add those newlines. I saw enough
weird software that is sensitive where it's should not bee.

-- Pete


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: sysfs output without newlines
  2020-09-01 22:22       ` Pete Zaitcev
@ 2020-09-02  7:57         ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2020-09-02  7:57 UTC (permalink / raw)
  To: Pete Zaitcev
  Cc: linux-wireless, Ulf Hansson, linux-usb, Rafael J. Wysocki,
	linux-mmc, Kai Mäkisara, Gustavo A . R . Silva, linux-i3c,
	Maxim Levitsky, linux-scsi, Madalin Bucur, Michal Simek,
	Alex Dewar, linux-arm-kernel, Jakub Kicinski, Tomas Winkler,
	Arnd Bergmann, platform-driver-x86, Robert Richter, Kees Cook,
	Alex Dubov, James E.J. Bottomley, Denis Efremov, Mark Brown,
	Borislav Petkov, Darren Hart, Mauro Carvalho Chehab, York Sun,
	Kalle Valo, linux-edac, Tony Luck, Martin K. Petersen,
	Boris Brezillon, Greg Kroah-Hartman, Oliver Neukum,
	Douglas Miller, LKML, linux-spi, Julia Lawall, David Laight,
	James Morse, Stanislav Yakovlev, netdev, Joe Perches,
	David S. Miller, Andy Shevchenko

On Wed, Sep 2, 2020 at 1:24 AM Pete Zaitcev <zaitcev@redhat.com> wrote:
>
> On Tue, 1 Sep 2020 09:07:42 +0000
> David Laight <David.Laight@ACULAB.COM> wrote:
>
> > The shell will remove trailing '\n' (but not '\r') from:
> >       foo=$(cat bar)
> > So shell scripts are unlikely to be affected.
>
> Surprisingly enough, Python is okay with this:
>
>     with open("/proc/sys/net/ipv4/ip_forward",'r') as fp:
>         print(int(fp.read()))
>
> Nonetheless, I would rather no add those newlines. I saw enough
> weird software that is sensitive where it's should not bee.

There are still a lot of scripts in PHP and Perl. Besides that I think
the many users of such files are in clouds, means Go should be checked
even before these.

-- 
With Best Regards,
Andy Shevchenko

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-09-02  7:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-29 18:23 sysfs output without newlines Joe Perches
2020-08-29 20:23 ` Denis Efremov
2020-08-29 20:33   ` Joe Perches
2020-09-01  9:07     ` David Laight
2020-09-01 22:22       ` Pete Zaitcev
2020-09-02  7:57         ` Andy Shevchenko
2020-08-30  9:11 ` Greg Kroah-Hartman

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