* [PATCH v3 0/2] x86: fix build warning int-to-pointer-cast
@ 2020-04-23 12:39 Vamshi K Sthambamkadi
2020-04-23 12:39 ` [PATCH v3 1/2] x86: add kstrtoul() converter func to boot code Vamshi K Sthambamkadi
2020-04-23 12:39 ` [PATCH v3 2/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
0 siblings, 2 replies; 5+ messages in thread
From: Vamshi K Sthambamkadi @ 2020-04-23 12:39 UTC (permalink / raw)
To: bp, tglx, mingo, hpa; +Cc: Vamshi K Sthambamkadi, x86, linux-kernel
Please review.
Changes in v3:
Copied kstrtoul & _kstrtoul correctly from lib/kstrtox.c to boot code
as suggested by Borislav petkov <bp@alien8.de>
Changes in v2:
On 32 bit, if supplied physical address overflow acpi_rsdp pointer
return 0 from get_cmdline_acpi_rsdp()
as suggested by Borislav Petkov <bp@alien8.de>
Changes in v1:
Supressed build warning through Makefile change
Thank you!
Vamshi K Sthambamkadi (2):
x86: add kstrtoul() converter func to boot code
x86: fix build warning int-to-pointer-cast
arch/x86/boot/compressed/acpi.c | 6 +++---
arch/x86/boot/string.c | 43 +++++++++++++++++++++++++++++++++++++++++
arch/x86/boot/string.h | 1 +
3 files changed, 47 insertions(+), 3 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] x86: add kstrtoul() converter func to boot code
2020-04-23 12:39 [PATCH v3 0/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
@ 2020-04-23 12:39 ` Vamshi K Sthambamkadi
2020-05-04 16:52 ` [tip: x86/boot] x86/boot: Add kstrtoul() from lib/ tip-bot2 for Vamshi K Sthambamkadi
2020-04-23 12:39 ` [PATCH v3 2/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
1 sibling, 1 reply; 5+ messages in thread
From: Vamshi K Sthambamkadi @ 2020-04-23 12:39 UTC (permalink / raw)
To: bp, tglx, mingo, hpa; +Cc: Vamshi K Sthambamkadi, x86, linux-kernel
add str to unsigned long converter function to boot code.
Signed-off-by: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
---
arch/x86/boot/string.c | 43 +++++++++++++++++++++++++++++++++++++++++++
arch/x86/boot/string.h | 1 +
2 files changed, 44 insertions(+)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 8272a44..e06ebe1 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -335,3 +335,46 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
s++;
return _kstrtoull(s, base, res);
}
+
+/* Internal, do not use. */
+int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long)tmp)
+ return -ERANGE;
+ *res = tmp;
+ return 0;
+}
+
+/**
+ * kstrtoul - convert a string to an unsigned long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the simple_strtoull.
+ */
+int kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ /*
+ * We want to shortcut function call, but
+ * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
+ */
+ if (sizeof(unsigned long) == sizeof(unsigned long long) &&
+ __alignof__(unsigned long) == __alignof__(unsigned long long))
+ return kstrtoull(s, base, (unsigned long long *)res);
+ else
+ return _kstrtoul(s, base, res);
+}
diff --git a/arch/x86/boot/string.h b/arch/x86/boot/string.h
index 38d8f2f..e8dd239 100644
--- a/arch/x86/boot/string.h
+++ b/arch/x86/boot/string.h
@@ -30,4 +30,5 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp,
unsigned int base);
int kstrtoull(const char *s, unsigned int base, unsigned long long *res);
+int kstrtoul(const char *s, unsigned int base, unsigned long *res);
#endif /* BOOT_STRING_H */
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] x86: fix build warning int-to-pointer-cast
2020-04-23 12:39 [PATCH v3 0/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
2020-04-23 12:39 ` [PATCH v3 1/2] x86: add kstrtoul() converter func to boot code Vamshi K Sthambamkadi
@ 2020-04-23 12:39 ` Vamshi K Sthambamkadi
2020-05-04 16:52 ` [tip: x86/boot] x86/boot: Fix -Wint-to-pointer-cast build warning tip-bot2 for Vamshi K Sthambamkadi
1 sibling, 1 reply; 5+ messages in thread
From: Vamshi K Sthambamkadi @ 2020-04-23 12:39 UTC (permalink / raw)
To: bp, tglx, mingo, hpa; +Cc: Vamshi K Sthambamkadi, x86, linux-kernel
Fix warning on x86_32:
arch/x86/boot/compressed/acpi.c:316:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
This is because on 32 bit, cast of acpi_physical_address(u64) to rsdp
pointer in get_acpi_srat_table() triggers this warning.
Signed-off-by: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
---
arch/x86/boot/compressed/acpi.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
index ef2ad72..2fd81f1 100644
--- a/arch/x86/boot/compressed/acpi.c
+++ b/arch/x86/boot/compressed/acpi.c
@@ -280,9 +280,9 @@ acpi_physical_address get_rsdp_addr(void)
*/
#define MAX_ADDR_LEN 19
-static acpi_physical_address get_cmdline_acpi_rsdp(void)
+static unsigned long get_cmdline_acpi_rsdp(void)
{
- acpi_physical_address addr = 0;
+ unsigned long addr = 0;
#ifdef CONFIG_KEXEC
char val[MAX_ADDR_LEN] = { };
@@ -292,7 +292,7 @@ static acpi_physical_address get_cmdline_acpi_rsdp(void)
if (ret < 0)
return 0;
- if (kstrtoull(val, 16, &addr))
+ if (kstrtoul(val, 16, &addr))
return 0;
#endif
return addr;
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: x86/boot] x86/boot: Fix -Wint-to-pointer-cast build warning
2020-04-23 12:39 ` [PATCH v3 2/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
@ 2020-05-04 16:52 ` tip-bot2 for Vamshi K Sthambamkadi
0 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Vamshi K Sthambamkadi @ 2020-05-04 16:52 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Vamshi K Sthambamkadi, Borislav Petkov, x86, LKML
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 40ba9309c76f29d012a5cc0cf938f8ff7dc6fef2
Gitweb: https://git.kernel.org/tip/40ba9309c76f29d012a5cc0cf938f8ff7dc6fef2
Author: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
AuthorDate: Thu, 23 Apr 2020 18:09:48 +05:30
Committer: Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 04 May 2020 15:22:16 +02:00
x86/boot: Fix -Wint-to-pointer-cast build warning
Fix this warning when building 32-bit with
CONFIG_RANDOMIZE_BASE=y
CONFIG_MEMORY_HOTREMOVE=y
arch/x86/boot/compressed/acpi.c:316:9: warning: \
cast to pointer from integer of different size [-Wint-to-pointer-cast]
Have get_cmdline_acpi_rsdp() return unsigned long which is the proper
type to convert to a pointer of the respective width.
[ bp: Rewrite commit message, touch ups. ]
Signed-off-by: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/1587645588-7130-3-git-send-email-vamshi.k.sthambamkadi@gmail.com
---
arch/x86/boot/compressed/acpi.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
index ef2ad72..8bcbcee 100644
--- a/arch/x86/boot/compressed/acpi.c
+++ b/arch/x86/boot/compressed/acpi.c
@@ -280,9 +280,9 @@ acpi_physical_address get_rsdp_addr(void)
*/
#define MAX_ADDR_LEN 19
-static acpi_physical_address get_cmdline_acpi_rsdp(void)
+static unsigned long get_cmdline_acpi_rsdp(void)
{
- acpi_physical_address addr = 0;
+ unsigned long addr = 0;
#ifdef CONFIG_KEXEC
char val[MAX_ADDR_LEN] = { };
@@ -292,7 +292,7 @@ static acpi_physical_address get_cmdline_acpi_rsdp(void)
if (ret < 0)
return 0;
- if (kstrtoull(val, 16, &addr))
+ if (boot_kstrtoul(val, 16, &addr))
return 0;
#endif
return addr;
@@ -314,7 +314,6 @@ static unsigned long get_acpi_srat_table(void)
* different ideas about whether to trust a command-line parameter.
*/
rsdp = (struct acpi_table_rsdp *)get_cmdline_acpi_rsdp();
-
if (!rsdp)
rsdp = (struct acpi_table_rsdp *)(long)
boot_params->acpi_rsdp_addr;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: x86/boot] x86/boot: Add kstrtoul() from lib/
2020-04-23 12:39 ` [PATCH v3 1/2] x86: add kstrtoul() converter func to boot code Vamshi K Sthambamkadi
@ 2020-05-04 16:52 ` tip-bot2 for Vamshi K Sthambamkadi
0 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Vamshi K Sthambamkadi @ 2020-05-04 16:52 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Vamshi K Sthambamkadi, Borislav Petkov, x86, LKML
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 5fafbebc86a0043ca5bbd8d3ce4f63dc5a02ad8e
Gitweb: https://git.kernel.org/tip/5fafbebc86a0043ca5bbd8d3ce4f63dc5a02ad8e
Author: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
AuthorDate: Thu, 23 Apr 2020 18:09:47 +05:30
Committer: Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 04 May 2020 15:19:07 +02:00
x86/boot: Add kstrtoul() from lib/
Add kstrtoul() to ../boot/ to be used by facilities there too.
[
bp: Massage, make _kstrtoul() static. Prepend function names with
"boot_". This is a temporary workaround for build errors like:
ld: arch/x86/boot/compressed/acpi.o: in function `count_immovable_mem_regions':
acpi.c:(.text+0x463): undefined reference to `_kstrtoul'
make[2]: *** [arch/x86/boot/compressed/Makefile:117: arch/x86/boot/compressed/vmlinux] Error 1
due to the namespace clash between x86/boot/ and kernel proper.
Future reorg will get rid of the linux/linux/ namespace as much as
possible so that x86/boot/ can be independent from kernel proper. ]
Signed-off-by: Vamshi K Sthambamkadi <vamshi.k.sthambamkadi@gmail.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/1587645588-7130-2-git-send-email-vamshi.k.sthambamkadi@gmail.com
---
arch/x86/boot/string.c | 43 ++++++++++++++++++++++++++++++++++++++++-
arch/x86/boot/string.h | 1 +-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 8272a44..8a3fff9 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -117,7 +117,6 @@ static unsigned int simple_guess_base(const char *cp)
* @endp: A pointer to the end of the parsed string will be placed here
* @base: The number base to use
*/
-
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
{
unsigned long long result = 0;
@@ -335,3 +334,45 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
s++;
return _kstrtoull(s, base, res);
}
+
+static int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ unsigned long long tmp;
+ int rv;
+
+ rv = kstrtoull(s, base, &tmp);
+ if (rv < 0)
+ return rv;
+ if (tmp != (unsigned long)tmp)
+ return -ERANGE;
+ *res = tmp;
+ return 0;
+}
+
+/**
+ * kstrtoul - convert a string to an unsigned long
+ * @s: The start of the string. The string must be null-terminated, and may also
+ * include a single newline before its terminating null. The first character
+ * may also be a plus sign, but not a minus sign.
+ * @base: The number base to use. The maximum supported base is 16. If base is
+ * given as 0, then the base of the string is automatically detected with the
+ * conventional semantics - If it begins with 0x the number will be parsed as a
+ * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
+ * parsed as an octal number. Otherwise it will be parsed as a decimal.
+ * @res: Where to write the result of the conversion on success.
+ *
+ * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
+ * Used as a replacement for the simple_strtoull.
+ */
+int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res)
+{
+ /*
+ * We want to shortcut function call, but
+ * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
+ */
+ if (sizeof(unsigned long) == sizeof(unsigned long long) &&
+ __alignof__(unsigned long) == __alignof__(unsigned long long))
+ return kstrtoull(s, base, (unsigned long long *)res);
+ else
+ return _kstrtoul(s, base, res);
+}
diff --git a/arch/x86/boot/string.h b/arch/x86/boot/string.h
index 38d8f2f..995f7b7 100644
--- a/arch/x86/boot/string.h
+++ b/arch/x86/boot/string.h
@@ -30,4 +30,5 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp,
unsigned int base);
int kstrtoull(const char *s, unsigned int base, unsigned long long *res);
+int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res);
#endif /* BOOT_STRING_H */
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-05-04 16:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 12:39 [PATCH v3 0/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
2020-04-23 12:39 ` [PATCH v3 1/2] x86: add kstrtoul() converter func to boot code Vamshi K Sthambamkadi
2020-05-04 16:52 ` [tip: x86/boot] x86/boot: Add kstrtoul() from lib/ tip-bot2 for Vamshi K Sthambamkadi
2020-04-23 12:39 ` [PATCH v3 2/2] x86: fix build warning int-to-pointer-cast Vamshi K Sthambamkadi
2020-05-04 16:52 ` [tip: x86/boot] x86/boot: Fix -Wint-to-pointer-cast build warning tip-bot2 for Vamshi K Sthambamkadi
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).