All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "liuqi (BA)" <liuqi115@huawei.com>,
	john.garry@huawei.com, zhangshaokun@hisilicon.com,
	will@kernel.org, mark.rutland@arm.com
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linuxarm@openeuler.org
Subject: Re: [Linuxarm] Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
Date: Thu, 18 Mar 2021 06:33:25 -0700	[thread overview]
Message-ID: <50b9ca002b7ce6c34a9c5d32126f667ec2c714b0.camel@perches.com> (raw)
In-Reply-To: <a2ccfc0f-5790-ef03-d357-ab606f40b3c5@huawei.com>

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");



WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: "liuqi (BA)" <liuqi115@huawei.com>,
	john.garry@huawei.com,  zhangshaokun@hisilicon.com,
	will@kernel.org, mark.rutland@arm.com
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  linuxarm@openeuler.org
Subject: Re: [Linuxarm] Re: [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at
Date: Thu, 18 Mar 2021 06:33:25 -0700	[thread overview]
Message-ID: <50b9ca002b7ce6c34a9c5d32126f667ec2c714b0.camel@perches.com> (raw)
In-Reply-To: <a2ccfc0f-5790-ef03-d357-ab606f40b3c5@huawei.com>

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");



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

  reply	other threads:[~2021-03-18 13:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17  9:41 [PATCH 0/3] drivers/perf: convert sysfs sprintf/snprintf/scnprintf to sysfs_emit Qi Liu
2021-03-17  9:41 ` Qi Liu
2021-03-17  9:41 ` [PATCH 1/3] drivers/perf: convert sysfs snprintf family " Qi Liu
2021-03-17  9:41   ` Qi Liu
2021-03-17  9:41 ` [PATCH 2/3] drivers/perf: convert sysfs scnprintf family to sysfs_emit_at Qi Liu
2021-03-17  9:41   ` Qi Liu
2021-03-17 13:47   ` kernel test robot
2021-03-17 13:47     ` kernel test robot
2021-03-17 13:47     ` kernel test robot
2021-03-17 14:29   ` kernel test robot
2021-03-17 14:29     ` kernel test robot
2021-03-17 14:29     ` kernel test robot
2021-03-17 14:57   ` Joe Perches
2021-03-17 14:57     ` Joe Perches
2021-03-18  9:33     ` [Linuxarm] " liuqi (BA)
2021-03-18  9:33       ` liuqi (BA)
2021-03-18 13:33       ` Joe Perches [this message]
2021-03-18 13:33         ` Joe Perches
2021-03-17 15:44   ` kernel test robot
2021-03-17 15:44     ` kernel test robot
2021-03-17 15:44     ` kernel test robot
2021-03-17  9:41 ` [PATCH 3/3] drivers/perf: convert sysfs sprintf family to sysfs_emit Qi Liu
2021-03-17  9:41   ` Qi Liu

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=50b9ca002b7ce6c34a9c5d32126f667ec2c714b0.camel@perches.com \
    --to=joe@perches.com \
    --cc=john.garry@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@openeuler.org \
    --cc=liuqi115@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=will@kernel.org \
    --cc=zhangshaokun@hisilicon.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.