amd-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Luben Tuikov <luben.tuikov@amd.com>
To: Felix Kuehling <felix.kuehling@amd.com>, amd-gfx@lists.freedesktop.org
Cc: Alexander Deucher <Alexander.Deucher@amd.com>,
	John Clements <john.clements@amd.com>,
	Hawking Zhang <Hawking.Zhang@amd.com>
Subject: Re: [PATCH] drm/amdgpu: Add double-sscanf but invert
Date: Wed, 14 Apr 2021 13:10:16 -0400	[thread overview]
Message-ID: <850b882e-a275-a316-4bd6-b75aebf82027@amd.com> (raw)
In-Reply-To: <cef16c21-0399-aa94-72bc-ef88089e3bb3@amd.com>

Yeah, %i would do, and certainly more elegant, except
for the signed input. Not sure if that's a problem, either,
thus the two sscanf...

Regards,
Luben

On 2021-04-14 11:58 a.m., Felix Kuehling wrote:
> From the sscanf manpage:
> 
>        i      Matches  an optionally signed integer; the next pointer
> must be
>               a pointer to int.  The integer is read in base 16 if it 
> begins
>               with  0x  or  0X, in base 8 if it begins with 0, and in
> base 10
>               otherwise.  Only characters that correspond  to  the 
> base  are
>               used.
> 
> So a single sscanf("%*s %i", ...) would to the job. The only problem is
> that accepts signed integers, not unsigned. I'm not sure if that's a
> problem in this use case.
> 
> Regards,
>   Felix
> 
> Am 2021-04-14 um 11:21 a.m. schrieb Luben Tuikov:
>> Add back the double-sscanf so that both decimal
>> and hexadecimal values could be read in, but this
>> time invert the scan so that hexadecimal format
>> with a leading 0x is tried first, and if that
>> fails, then try decimal format.
>>
>> Also use a logical-AND instead of nesting double
>> if-conditional.
>>
>> See commit "drm/amdgpu: Fix a bug for input with double sscanf"
>>
>> Cc: Alexander Deucher <Alexander.Deucher@amd.com>
>> Cc: John Clements <john.clements@amd.com>
>> Cc: Hawking Zhang <Hawking.Zhang@amd.com>
>> Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
>> ---
>>  drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
>> index 44dfb3613e37..38a691a3b600 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
>> @@ -229,7 +229,8 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
>>  
>>  	if (op != -1) {
>>  		if (op == 3) {
>> -			if (sscanf(str, "%*s %llx", &address) != 1)
>> +			if (sscanf(str, "%*s 0x%llx", &address) != 1 &&
>> +			    sscanf(str, "%*s %llu", &address) != 1)
>>  				return -EINVAL;
>>  
>>  			data->op = op;
>> @@ -253,7 +254,9 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
>>  		data->op = op;
>>  
>>  		if (op == 2) {
>> -			if (sscanf(str, "%*s %*s %*s %x %llx %llx",
>> +			if (sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx",
>> +				   &sub_block, &address, &value) != 3 &&
>> +			    sscanf(str, "%*s %*s %*s %u %llu %llu",
>>  				   &sub_block, &address, &value) != 3)
>>  				return -EINVAL;
>>  			data->head.sub_block_index = sub_block;

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

      reply	other threads:[~2021-04-14 17:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 15:21 [PATCH] drm/amdgpu: Add double-sscanf but invert Luben Tuikov
2021-04-14 15:27 ` Luben Tuikov
2021-04-14 15:58 ` Felix Kuehling
2021-04-14 17:10   ` Luben Tuikov [this message]

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=850b882e-a275-a316-4bd6-b75aebf82027@amd.com \
    --to=luben.tuikov@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=felix.kuehling@amd.com \
    --cc=john.clements@amd.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 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).