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] [day] [month] [year] [list]
Date:   Thu, 18 Mar 2021 06:33:25 -0700
From:   Joe Perches <joe@...ches.com>
To:     "liuqi (BA)" <liuqi115@...wei.com>, john.garry@...wei.com,
        zhangshaokun@...ilicon.com, will@...nel.org, mark.rutland@....com
Cc:     linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        linuxarm@...neuler.org
Subject: Re: [Linuxarm] Re: [PATCH 2/3] drivers/perf: convert sysfs
 scnprintf family to sysfs_emit_at

On Thu, 2021-03-18 at 17:33 +0800, liuqi (BA) wrote:
> On 2021/3/17 22:57, Joe Perches wrote:
> > On Wed, 2021-03-17 at 17:41 +0800, Qi Liu wrote:
> > > Use the generic sysfs_emit_at() function take place of scnprintf()
> > []
> > > diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c
> > []
> > > @@ -328,41 +328,37 @@ static ssize_t arm_ccn_pmu_event_show(struct device *dev,
> > >   			struct arm_ccn_pmu_event, attr);
> > >   	ssize_t res;
> > >   
> > > 
> > > 
> > > -	res = scnprintf(buf, PAGE_SIZE, "type=0x%x", event->type);
> > > +	res = sysfs_emit(buf, "type=0x%x", event->type);
> > >   	if (event->event)
> > > -		res += scnprintf(buf + res, PAGE_SIZE - res, ",event=0x%x",
> > > +		res += sysfs_emit_at(buf + res, res, ",event=0x%x",
> > >   				event->event);
> > 
> > sysfs_emit_at should always use buf, not buf + offset.
> > res should be int and is the offset from buf for the output
> > 
> > so the form should be similar to
> > 
> > 	int len;
> > 
> > 	len = sysfs_emit(buf, "type=0x%x", event->type);
> > 	if (event->event) {
> > 		len += sysfs_emit_at(buf, len, ",event=0x%x", event->event);
> > 
> > 		etc...
> > 
> Hi Joe,
> 
> I'll fix the use of sysfs_emit_at in next version, thanks.
> But I think it's better to keep the res as ssize_t, as the return value 
> of this function is ssize_t.

The 2nd arg of sysfs_emit_at is int.
On 64 bit platforms, ssize_t is 64 bit while int is 32.

If res (or len) is ssize_t, there could be a lot of -Wconversion warnings
like this produced when using make W=

warning: conversion from ‘ssize_t’ {aka ‘long int’} to ‘int’ may change value [-Wconversion]
  262 |  len += sysfs_emit_at(buf, len, "\n");


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ