From: Laszlo Ersek <lersek@redhat.com>
To: Eric Blake <eblake@redhat.com>,
"Gabriel L. Somlo" <somlo@cmu.edu>,
kbuild test robot <lkp@intel.com>
Cc: mark.rutland@arm.com, peter.maydell@linaro.org, mst@redhat.com,
stefanha@gmail.com, qemu-devel@nongnu.org, eric@anholt.net,
kraxel@redhat.com, linux-api@vger.kernel.org, pawel.moll@arm.com,
zajec5@gmail.com, galak@codeaurora.org,
rmk+kernel@arm.linux.org.uk, hanjun.guo@linaro.org,
devicetree@vger.kernel.org, arnd@arndb.de,
ijc+devicetree@hellion.org.uk, jordan.l.justen@intel.com,
agross@codeaurora.org, leif.lindholm@linaro.org,
robh+dt@kernel.org, ard.biesheuvel@linaro.org,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
luto@amacapital.net, kbuild-all@01.org, sudeep.holla@arm.com,
pbonzini@redhat.com, revol@free.fr
Subject: Re: [Qemu-devel] [PATCH v5 1/4] firmware: introduce sysfs driver for QEMU's fw_cfg device
Date: Tue, 24 Nov 2015 18:44:33 +0100 [thread overview]
Message-ID: <5654A201.2070902@redhat.com> (raw)
In-Reply-To: <5654A08A.6030002@redhat.com>
On 11/24/15 18:38, Eric Blake wrote:
> On 11/24/2015 09:55 AM, Gabriel L. Somlo wrote:
>> On Tue, Nov 24, 2015 at 04:14:50AM +0800, kbuild test robot wrote:
>
>>>
>>> drivers/firmware/qemu_fw_cfg.c: In function 'fw_cfg_cmdline_set':
>>>>> drivers/firmware/qemu_fw_cfg.c:510:7: warning: format '%lli' expects argument of type 'long long int *', but argument 3 has type 'phys_addr_t *' [-Wformat=]
>>> &ctrl_off, &data_off, &consumed);
>>> ^
>>
>> Oh, I think I know why this happened:
>>
>
>>
>> So, I could use u64 instead of phys_addr_t and resource_size_t, and
>> keep "%lli" (or "%Li"), but then I'd have to check if the parsed value
>
> %Li is not POSIX. Don't use it (stick with %lli).
>
>> would overflow a 32-bit address value on arches where phys_addr_t is
>> u32, which would make things a bit more messy and awkward.
>>
>> I'm planning on #ifdef-ing the format string instead:
>>
>> #ifdef CONFIG_PHYS_ADDR_T_64BIT
>> #define PH_ADDR_SCAN_FMT "@%Li%n:%Li:%Li%n"
>> #else
>> #define PH_ADDR_SCAN_FMT "@%li%n:%li:%li%n"
>> #endif
>
> A more typical approach is akin to <inttypes.h>; have PH_ADDR_FMT
> defined to either "lli" or "li", then write sscanf(str, "@%"PH_ADDR_FMT
> "%n:..., ...), using PH_ADDR_FMT multiple times.
>
>> ...
>> processed = sscanf(str, PH_ADDR_SCAN_FMT,
>> &base, &consumed,
>> &ctrl_off, &data_off, &consumed);
>
> Umm, why are you passing &consumed to more than one sscanf() %? That's
> (probably) undefined behavior.
>
> [In general, sscanf() is a horrid interface to use for parsing integers
> - it has undefined behavior if the input text would trigger integer
> overflow, making it safe to use ONLY on text that you control and can
> guarantee won't overflow. By the time you've figured out if untrusted
> text meets the requirement for safe parsing via sscanf(), you've
> practically already parsed it via safer strtol() and friends.]
>
Yes, but this is the kernel, which may or may not follow POSIX
semantics. (And may or may not curse at POSIX in the process, either
way! :))
Laszlo
next prev parent reply other threads:[~2015-11-24 17:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-23 15:57 [PATCH v5 0/4] SysFS driver for QEMU " Gabriel L. Somlo
2015-11-23 15:57 ` [PATCH v5 1/4] firmware: introduce sysfs driver for QEMU's " Gabriel L. Somlo
2015-11-23 20:14 ` kbuild test robot
2015-11-24 16:55 ` Gabriel L. Somlo
2015-11-24 17:38 ` [Qemu-devel] " Eric Blake
2015-11-24 17:44 ` Laszlo Ersek [this message]
2015-11-24 18:09 ` Gabriel L. Somlo
2015-11-23 15:57 ` [PATCH v5 2/4] kobject: export kset_find_obj() for module use Gabriel L. Somlo
2015-11-23 15:57 ` [PATCH v5 3/4] firmware: create directory hierarchy for sysfs fw_cfg entries Gabriel L. Somlo
2015-11-23 15:57 ` [PATCH v5 4/4] devicetree: update documentation for fw_cfg ARM bindings Gabriel L. Somlo
2015-11-23 16:35 ` Laszlo Ersek
2015-11-23 16:47 ` Gabriel L. Somlo
2015-11-25 2:42 ` Rob Herring
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=5654A201.2070902@redhat.com \
--to=lersek@redhat.com \
--cc=agross@codeaurora.org \
--cc=ard.biesheuvel@linaro.org \
--cc=arnd@arndb.de \
--cc=devicetree@vger.kernel.org \
--cc=eblake@redhat.com \
--cc=eric@anholt.net \
--cc=galak@codeaurora.org \
--cc=gregkh@linuxfoundation.org \
--cc=hanjun.guo@linaro.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=jordan.l.justen@intel.com \
--cc=kbuild-all@01.org \
--cc=kraxel@redhat.com \
--cc=leif.lindholm@linaro.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=luto@amacapital.net \
--cc=mark.rutland@arm.com \
--cc=mst@redhat.com \
--cc=pawel.moll@arm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=revol@free.fr \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=robh+dt@kernel.org \
--cc=somlo@cmu.edu \
--cc=stefanha@gmail.com \
--cc=sudeep.holla@arm.com \
--cc=zajec5@gmail.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
all inboxes | Powered by JetHome®