From ea5aeb986ca8061b45bfcc73df7285399d714fd0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 10:17:42 +0200 Subject: include: move run_command prototype to command.h run_command fits much better into command.h, move it there. Signed-off-by: Sascha Hauer --- common/menutree.c | 1 + common/password.c | 1 + drivers/usb/gadget/f_fastboot.c | 1 + fs/fs.c | 1 + include/command.h | 1 + include/common.h | 1 - 6 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/menutree.c b/common/menutree.c index 97e628de88..160ba9ac4b 100644 --- a/common/menutree.c +++ b/common/menutree.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/common/password.c b/common/password.c index 5b754d943f..05e61801f0 100644 --- a/common/password.c +++ b/common/password.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 0df08c9a2b..9a8cd4c844 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -17,6 +17,7 @@ #define pr_fmt(fmt) "fastboot: " fmt #include +#include #include #include #include diff --git a/fs/fs.c b/fs/fs.c index 440adae14c..d69e1e94cc 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include diff --git a/include/command.h b/include/command.h index 3aca1a9f1b..4ed5e37395 100644 --- a/include/command.h +++ b/include/command.h @@ -71,6 +71,7 @@ extern struct command __barebox_cmd_end; struct command *find_cmd(const char *cmd); int execute_command(int argc, char **argv); void barebox_cmd_usage(struct command *cmdtp); +int run_command(const char *cmd); #define COMMAND_SUCCESS 0 #define COMMAND_ERROR 1 diff --git a/include/common.h b/include/common.h index 38a6dbf933..f653c04565 100644 --- a/include/common.h +++ b/include/common.h @@ -61,7 +61,6 @@ void __noreturn hang (void); char *size_human_readable(unsigned long long size); -int run_command(const char *cmd); int readline (const char *prompt, char *buf, int len); /* common/memsize.c */ -- cgit v1.2.3 From 086d0026a0eadb40e3c5502042a7c20a0ffa1c4f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 10:20:58 +0200 Subject: include/common.h: remove unused struct memarea_info Signed-off-by: Sascha Hauer --- include/common.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/common.h b/include/common.h index f653c04565..cab98d62d8 100644 --- a/include/common.h +++ b/include/common.h @@ -87,16 +87,6 @@ static inline void dump_stack(void) } #endif -#define MEMAREA_SIZE_SPECIFIED 1 - -struct memarea_info { - struct device_d *device; - unsigned long start; - unsigned long end; - unsigned long size; - unsigned long flags; -}; - int parse_area_spec(const char *str, loff_t *start, loff_t *size); /* Just like simple_strtoul(), but this one honors a K/M/G suffix */ -- cgit v1.2.3 From 4e9f324d37e98823eb7179a239d412e9786d9938 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 12 Apr 2016 09:21:12 +0200 Subject: include: move shell prototypes to shell.h We have a shell,h, so move shell specific prototypes there. Signed-off-by: Sascha Hauer --- common/menutree.c | 1 + common/startup.c | 1 + include/common.h | 11 ----------- include/shell.h | 11 +++++++++++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/menutree.c b/common/menutree.c index 160ba9ac4b..1505ec8541 100644 --- a/common/menutree.c +++ b/common/menutree.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/common/startup.c b/common/startup.c index 093a23ba08..432be67cd6 100644 --- a/common/startup.c +++ b/common/startup.c @@ -30,6 +30,7 @@ * @brief Main entry into the C part of barebox */ #include +#include #include #include #include diff --git a/include/common.h b/include/common.h index cab98d62d8..ea349beb9a 100644 --- a/include/common.h +++ b/include/common.h @@ -102,17 +102,6 @@ extern int (*barebox_main)(void); void __noreturn start_barebox(void); void shutdown_barebox(void); -int run_shell(void); - -#ifdef CONFIG_SHELL_HUSH -char *shell_expand(char *str); -#else -static inline char *shell_expand(char *str) -{ - return strdup(str); -} -#endif - #define ALIGN_DOWN(x, a) ((x) & ~((typeof(x))(a) - 1)) #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x) diff --git a/include/shell.h b/include/shell.h index b98cac3dc5..65dad0e1d1 100644 --- a/include/shell.h +++ b/include/shell.h @@ -9,4 +9,15 @@ int shell_get_last_return_code(void); +int run_shell(void); + +#ifdef CONFIG_SHELL_HUSH +char *shell_expand(char *str); +#else +static inline char *shell_expand(char *str) +{ + return strdup(str); +} +#endif + #endif /* __SHELL_H__ */ -- cgit v1.2.3 From db33f32842973245f0adcae2fb7fd23ec4325630 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 10:50:12 +0200 Subject: include: move crc specific stuff to crc.h We have a crc.h, so move our crc function prototypes there to further cleanup common.h. Signed-off-by: Sascha Hauer --- arch/ppc/boards/geip-da923rc/product_data.c | 1 + commands/crc.c | 1 + common/environment.c | 1 + common/imx-bbu-nand-fcb.c | 1 + common/partitions/efi.c | 1 + common/state.c | 1 + common/uimage.c | 1 + crypto/crc32.c | 1 + drivers/mtd/ubi/ubi-barebox.h | 3 +- drivers/mtd/ubi/ubi.h | 1 + fs/bpkfs.c | 1 + fs/ubifs/ubifs.h | 1 + fs/uimagefs.c | 1 + include/common.h | 6 -- include/crc.h | 102 +++------------------------- 15 files changed, 22 insertions(+), 101 deletions(-) diff --git a/arch/ppc/boards/geip-da923rc/product_data.c b/arch/ppc/boards/geip-da923rc/product_data.c index 0c4600611a..eda10a4178 100644 --- a/arch/ppc/boards/geip-da923rc/product_data.c +++ b/arch/ppc/boards/geip-da923rc/product_data.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include diff --git a/commands/crc.c b/commands/crc.c index 58b750eb95..066d91e179 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/common/environment.c b/common/environment.c index 9cf44a0f06..65404afa14 100644 --- a/common/environment.c +++ b/common/environment.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c index 04c6e6050c..1ffa79d1ec 100644 --- a/common/imx-bbu-nand-fcb.c +++ b/common/imx-bbu-nand-fcb.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include diff --git a/common/partitions/efi.c b/common/partitions/efi.c index a9945dd9eb..88734f166b 100644 --- a/common/partitions/efi.c +++ b/common/partitions/efi.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "efi.h" diff --git a/common/state.c b/common/state.c index b55b1503bd..c763ca4a41 100644 --- a/common/state.c +++ b/common/state.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/common/uimage.c b/common/uimage.c index 59d7b65c90..34daf70dc1 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/crypto/crc32.c b/crypto/crc32.c index 58637bd770..3bff6feb28 100644 --- a/crypto/crc32.c +++ b/crypto/crc32.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/mtd/ubi/ubi-barebox.h b/drivers/mtd/ubi/ubi-barebox.h index ab970aa19d..557ad88316 100644 --- a/drivers/mtd/ubi/ubi-barebox.h +++ b/drivers/mtd/ubi/ubi-barebox.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -26,7 +27,7 @@ #include #include -#define crc32(seed, data, length) crc32_no_comp(seed, (unsigned char const *)data, length) +#define crc32(seed, data, length) crc32_no_comp(seed, (unsigned char * const)data, length) /* configurable */ #define CONFIG_MTD_UBI_WL_THRESHOLD 4096 diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index a8ed0d7710..471d784234 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include diff --git a/fs/bpkfs.c b/fs/bpkfs.c index 1e2619e5cd..309a122c19 100644 --- a/fs/bpkfs.c +++ b/fs/bpkfs.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 75e54e7fef..d2dcf7e180 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -34,6 +34,7 @@ #else #include #include +#include #include #include #include diff --git a/fs/uimagefs.c b/fs/uimagefs.c index 3fdc5bd2be..c2e34a7f32 100644 --- a/fs/uimagefs.c +++ b/fs/uimagefs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include static bool uimagefs_is_data_file(struct uimagefs_handle_data *d) diff --git a/include/common.h b/include/common.h index ea349beb9a..54120c447a 100644 --- a/include/common.h +++ b/include/common.h @@ -69,12 +69,6 @@ long get_ram_size (volatile long *, long); /* $(CPU)/cpu.c */ void __noreturn poweroff(void); -/* lib_generic/crc32.c */ -uint32_t crc32(uint32_t, const void*, unsigned int); -uint32_t crc32_no_comp(uint32_t, const void*, unsigned int); -int file_crc(char *filename, ulong start, ulong size, ulong *crc, - ulong *total); - /* common/console.c */ int ctrlc (void); diff --git a/include/crc.h b/include/crc.h index 4290f41c57..847a0a4b64 100644 --- a/include/crc.h +++ b/include/crc.h @@ -1,100 +1,14 @@ -/* - *========================================================================== - * - * crc.h - * - * Interface for the CRC algorithms. - * - *========================================================================== - *####ECOSGPLCOPYRIGHTBEGIN#### - * ------------------------------------------- - * This file is part of eCos, the Embedded Configurable Operating System. - * Copyright (C) 2002 Andrew Lunn - * - * eCos is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 or (at your option) any later version. - * - * eCos is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with eCos; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * As a special exception, if other files instantiate templates or use macros - * or inline functions from this file, or you compile this file and link it - * with other works to produce a work based on this file, this file does not - * by itself cause the resulting work to be covered by the GNU General Public - * License. However the source code for this file must still be made available - * in accordance with section (3) of the GNU General Public License. - * - * This exception does not invalidate any other reasons why a work based on - * this file might be covered by the GNU General Public License. - * - * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. - * at http: *sources.redhat.com/ecos/ecos-license/ - * ------------------------------------------- - *####ECOSGPLCOPYRIGHTEND#### - *========================================================================== - *#####DESCRIPTIONBEGIN#### - * - * Author(s): Andrew Lunn - * Contributors: Andrew Lunn - * Date: 2002-08-06 - * Purpose: - * Description: - * - * This code is part of eCos (tm). - * - *####DESCRIPTIONEND#### - * - *========================================================================== - */ - -#ifndef _SERVICES_CRC_CRC_H_ -#define _SERVICES_CRC_CRC_H_ +#ifndef __INCLUDE_CRC_H +#define __INCLUDE_CRC_H #include -#ifndef __externC -# ifdef __cplusplus -# define __externC extern "C" -# else -# define __externC extern -# endif -#endif - -/* Compute a CRC, using the POSIX 1003 definition */ -extern uint32_t -cyg_posix_crc32(unsigned char *s, int len); - -/* Gary S. Brown's 32 bit CRC */ - -extern uint32_t -cyg_crc32(unsigned char *s, int len); - -/* Gary S. Brown's 32 bit CRC, but accumulate the result from a */ -/* previous CRC calculation */ - -extern uint32_t -cyg_crc32_accumulate(uint32_t crc, unsigned char *s, int len); - -/* Ethernet FCS Algorithm */ - -extern uint32_t -cyg_ether_crc32(unsigned char *s, int len); - -/* Ethernet FCS algorithm, but accumulate the result from a previous */ -/* CRC calculation. */ - -extern uint32_t -cyg_ether_crc32_accumulate(uint32_t crc, unsigned char *s, int len); - /* 16 bit CRC with polynomial x^16+x^12+x^5+1 */ - extern uint16_t cyg_crc16(const unsigned char *s, int len); -#endif /* _SERVICES_CRC_CRC_H_ */ +uint32_t crc32(uint32_t, const void *, unsigned int); +uint32_t crc32_no_comp(uint32_t, const void *, unsigned int); +int file_crc(char *filename, unsigned long start, unsigned long size, + unsigned long *crc, unsigned long *total); + +#endif /* __INCLUDE_CRC_H */ -- cgit v1.2.3 From 4f17444eccebeeadeaed212568a202ef97f4e71f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 11:06:07 +0200 Subject: libfile: move open_and_lseek() to libfile libfile is a collection of helpers for handling files. open_and_lseek() is a perfect match for this, so move it there. Signed-off-by: Sascha Hauer --- commands/md.c | 1 + commands/mem.c | 23 ----------------------- commands/memcmp.c | 1 + commands/memcpy.c | 1 + commands/memset.c | 1 + commands/mm.c | 1 + commands/mw.c | 1 + include/common.h | 1 - include/libfile.h | 2 ++ lib/libfile.c | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 40 insertions(+), 24 deletions(-) diff --git a/commands/md.c b/commands/md.c index c88259a3f8..3e83c723a3 100644 --- a/commands/md.c +++ b/commands/md.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/commands/mem.c b/commands/mem.c index 23c703f0b5..907f1f76a8 100644 --- a/commands/mem.c +++ b/commands/mem.c @@ -41,29 +41,6 @@ char *mem_rw_buf; -int open_and_lseek(const char *filename, int mode, loff_t pos) -{ - int fd, ret; - - fd = open(filename, mode | O_RDONLY); - if (fd < 0) { - perror("open"); - return fd; - } - - if (!pos) - return fd; - - ret = lseek(fd, pos, SEEK_SET); - if (ret == -1) { - perror("lseek"); - close(fd); - return -errno; - } - - return fd; -} - /* * Common function for parsing options for the 'md', 'mw', 'memcpy', 'memcmp' * commands. diff --git a/commands/memcmp.c b/commands/memcmp.c index e079d5f78e..ce044df0d9 100644 --- a/commands/memcmp.c +++ b/commands/memcmp.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/commands/memcpy.c b/commands/memcpy.c index 9c8b64525c..168ef3b4fc 100644 --- a/commands/memcpy.c +++ b/commands/memcpy.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/commands/memset.c b/commands/memset.c index fc5b659b9b..f871e07c95 100644 --- a/commands/memset.c +++ b/commands/memset.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/commands/mm.c b/commands/mm.c index 7c890a6696..6d2a887892 100644 --- a/commands/mm.c +++ b/commands/mm.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/commands/mw.c b/commands/mw.c index 8ca3c61d7f..bb6a16ef3d 100644 --- a/commands/mw.c +++ b/commands/mw.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/include/common.h b/include/common.h index 54120c447a..680a0affb6 100644 --- a/include/common.h +++ b/include/common.h @@ -128,7 +128,6 @@ static inline void print_hex_dump(const char *level, const char *prefix_str, int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, char **sourcefile, char **destfile, int *swab); -int open_and_lseek(const char *filename, int mode, loff_t pos); #define RW_BUF_SIZE (unsigned)4096 extern const char version_string[]; diff --git a/include/libfile.h b/include/libfile.h index d5b914a47a..51fa06008f 100644 --- a/include/libfile.h +++ b/include/libfile.h @@ -19,4 +19,6 @@ int copy_recursive(const char *src, const char *dst); int compare_file(const char *f1, const char *f2); +int open_and_lseek(const char *filename, int mode, loff_t pos); + #endif /* __LIBFILE_H */ diff --git a/lib/libfile.c b/lib/libfile.c index a27460c10d..2c72ffe066 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -442,3 +442,35 @@ err_out1: close(fd1); return ret; } + +/** + * open_and_lseek - open file and lseek to position + * @filename: The file to open + * @mode: The file open mode + * @pos: The position to lseek to + * + * Return: If successful this function returns a positive filedescriptor + * number, otherwise a negative error code is returned + */ +int open_and_lseek(const char *filename, int mode, loff_t pos) +{ + int fd, ret; + + fd = open(filename, mode | O_RDONLY); + if (fd < 0) { + perror("open"); + return fd; + } + + if (!pos) + return fd; + + ret = lseek(fd, pos, SEEK_SET); + if (ret == -1) { + perror("lseek"); + close(fd); + return -errno; + } + + return fd; +} -- cgit v1.2.3 From 48b205e32342fc8a2648b2bd3f1f6d9a7d74e6cb Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 15:44:13 +0200 Subject: show_progress: print spaces with %*s Removes the need for include/linux/stringify.h in the progress bar code. Signed-off-by: Sascha Hauer --- lib/show_progress.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/show_progress.c b/lib/show_progress.c index f9aa1a945e..a32a13c16d 100644 --- a/lib/show_progress.c +++ b/lib/show_progress.c @@ -21,7 +21,6 @@ #include #include #include -#include #define HASHES_PER_LINE 65 @@ -58,7 +57,7 @@ void init_progression_bar(int max) progress_max = max; spin = 0; if (progress_max && progress_max != FILESIZE_MAX) - printf("\t[%"__stringify(HASHES_PER_LINE)"s]\r\t[", ""); + printf("\t[%*s]\r\t[", HASHES_PER_LINE, ""); else printf("\t"); } -- cgit v1.2.3 From 947fb5adf8af450507c978abf1c7ec9f051e5842 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 16:52:10 +0200 Subject: string: Fix (v)asprintf prototypes Our asprintf and vasprintf have different prototypes than the glibc functions. This causes trouble when we want to share barebox code with userspace code. Change the prototypes for (v)asprintf to match the glibc prototypes. Since the current (v)asprintf are convenient to use change the existing functions to b(v)asprintf. Signed-off-by: Sascha Hauer --- arch/arm/boards/edb93xx/edb93xx.c | 2 +- arch/arm/boards/embedsky-e9/board.c | 4 +-- arch/arm/boards/phytec-som-imx6/board.c | 10 +++---- arch/arm/boards/raspberry-pi/rpi-common.c | 6 ++-- arch/arm/mach-imx/iim.c | 2 +- arch/arm/mach-omap/omap_generic.c | 2 +- arch/arm/mach-omap/xload.c | 4 +-- commands/boot.c | 6 ++-- commands/clk.c | 2 +- commands/crc.c | 4 +-- commands/defaultenv.c | 4 +-- commands/hashsum.c | 2 +- commands/tftp.c | 4 +-- common/blspec.c | 34 +++++++++++----------- common/bootargs.c | 6 ++-- common/console.c | 4 +-- common/env.c | 2 +- common/environment.c | 4 +-- common/firmware.c | 2 +- common/globalvar.c | 7 +++-- common/menutree.c | 4 +-- common/partitions.c | 2 +- common/state.c | 4 +-- crypto/hmac.c | 4 +-- drivers/ata/disk_ata_drive.c | 2 +- drivers/ata/disk_bios_drive.c | 2 +- drivers/eeprom/at24.c | 2 +- drivers/mci/mci-core.c | 6 ++-- drivers/mfd/stmpe-i2c.c | 4 +-- drivers/misc/sram.c | 3 +- drivers/mtd/core.c | 12 ++++---- drivers/mtd/devices/docg3.c | 4 +-- drivers/mtd/mtdoob.c | 2 +- drivers/mtd/mtdraw.c | 2 +- drivers/mtd/nand/nand-bb.c | 2 +- drivers/mtd/ubi/barebox.c | 4 +-- drivers/net/ksz8864rmn.c | 2 +- drivers/of/barebox.c | 2 +- drivers/of/base.c | 3 +- drivers/of/of_path.c | 2 +- drivers/of/partition.c | 2 +- drivers/pci/pci-mvebu.c | 4 +-- drivers/pinctrl/pinctrl.c | 2 +- drivers/pwm/pwm-imx.c | 5 ++-- drivers/pwm/pwm-mxs.c | 2 +- drivers/pwm/pxa_pwm.c | 2 +- drivers/regulator/core.c | 2 +- drivers/spi/gpio_spi.c | 2 +- drivers/usb/gadget/composite.c | 2 +- drivers/usb/gadget/f_fastboot.c | 7 +++-- drivers/usb/storage/usb.c | 2 +- drivers/video/edid.c | 9 ++++-- drivers/video/fb.c | 2 +- drivers/video/imx-ipu-v3/imx-ldb.c | 8 +++--- drivers/video/imx-ipu-v3/ipu-di.c | 3 +- drivers/video/imx-ipu-v3/ipufb.c | 2 +- drivers/w1/slaves/w1_ds2431.c | 2 +- drivers/w1/slaves/w1_ds2433.c | 2 +- fs/bpkfs.c | 6 ++-- fs/efi.c | 4 +-- fs/efivarfs.c | 4 +-- fs/fs.c | 7 +++-- fs/nfs.c | 9 +++--- fs/ubifs/ubifs.c | 4 +-- fs/uimagefs.c | 10 +++---- include/stdio.h | 6 ++-- include/w1_mac_address.h | 2 +- lib/libfile.c | 6 ++-- lib/logo/logo.c | 2 +- lib/parameter.c | 8 +++--- lib/stringlist.c | 2 +- lib/uncompress.c | 3 +- lib/vsprintf.c | 48 +++++++++++++++++++++++++------ lib/xfuncs.c | 2 +- net/dhcp.c | 6 ++-- net/dns.c | 4 +-- net/ifup.c | 4 +-- 77 files changed, 211 insertions(+), 165 deletions(-) diff --git a/arch/arm/boards/edb93xx/edb93xx.c b/arch/arm/boards/edb93xx/edb93xx.c index 0fb93d23dc..3b8e668e35 100644 --- a/arch/arm/boards/edb93xx/edb93xx.c +++ b/arch/arm/boards/edb93xx/edb93xx.c @@ -123,7 +123,7 @@ static int edb93xx_console_init(void) else shortname = "unknown"; - board = asprintf("Cirrus Logic %s", shortname); + board = basprintf("Cirrus Logic %s", shortname); barebox_set_model(board); free(board); barebox_set_hostname(shortname); diff --git a/arch/arm/boards/embedsky-e9/board.c b/arch/arm/boards/embedsky-e9/board.c index 23bfec1b77..251bfee65b 100644 --- a/arch/arm/boards/embedsky-e9/board.c +++ b/arch/arm/boards/embedsky-e9/board.c @@ -70,8 +70,8 @@ static int e9_devices_init(void) armlinux_set_architecture(3980); - environment_path = asprintf("/chosen/environment-mmc%d", - bootsource_get_instance()); + environment_path = basprintf("/chosen/environment-mmc%d", + bootsource_get_instance()); ret = of_device_enable_path(environment_path); diff --git a/arch/arm/boards/phytec-som-imx6/board.c b/arch/arm/boards/phytec-som-imx6/board.c index 85ad8cb5e2..bf8703e3a4 100644 --- a/arch/arm/boards/phytec-som-imx6/board.c +++ b/arch/arm/boards/phytec-som-imx6/board.c @@ -124,20 +124,20 @@ static int physom_imx6_devices_init(void) switch (bootsource_get()) { case BOOTSOURCE_MMC: - environment_path = asprintf("/chosen/environment-sd%d", - bootsource_get_instance() + 1); + environment_path = basprintf("/chosen/environment-sd%d", + bootsource_get_instance() + 1); envdev = "MMC"; break; case BOOTSOURCE_NAND: - environment_path = asprintf("/chosen/environment-nand"); + environment_path = basprintf("/chosen/environment-nand"); envdev = "NAND flash"; break; case BOOTSOURCE_SPI: - environment_path = asprintf("/chosen/environment-spinor"); + environment_path = basprintf("/chosen/environment-spinor"); envdev = "SPI NOR flash"; break; default: - environment_path = asprintf(default_environment_path); + environment_path = basprintf(default_environment_path); envdev = default_envdev; break; } diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c index 0e17587a74..147fce9952 100644 --- a/arch/arm/boards/raspberry-pi/rpi-common.c +++ b/arch/arm/boards/raspberry-pi/rpi-common.c @@ -201,8 +201,8 @@ static void rpi_get_board_rev(void) if (!rpi_board_rev) goto unknown_rev; - name = asprintf("RaspberryPi %s %s", rpi_models[rpi_board_rev].name, - rpi_model_string); + name = basprintf("RaspberryPi %s %s", + rpi_models[rpi_board_rev].name, rpi_model_string); barebox_set_model(name); free(name); @@ -210,7 +210,7 @@ static void rpi_get_board_rev(void) unknown_rev: rpi_board_rev = 0; - name = asprintf("RaspberryPi %s", rpi_model_string); + name = basprintf("RaspberryPi %s", rpi_model_string); barebox_set_model(name); free(name); } diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c index dbd8ccf054..ecaa7e6332 100644 --- a/arch/arm/mach-imx/iim.c +++ b/arch/arm/mach-imx/iim.c @@ -330,7 +330,7 @@ static void imx_iim_add_mac_param(struct iim_priv *iim, int macnum, int bank, in iimmac->offset = offset; iimmac->bank = iim->bank[bank]; - name = asprintf("ethaddr%d", macnum); + name = basprintf("ethaddr%d", macnum); dev_add_param_mac(&iim->dev, name, imx_iim_set_mac, imx_iim_get_mac, iimmac->ethaddr, iimmac); diff --git a/arch/arm/mach-omap/omap_generic.c b/arch/arm/mach-omap/omap_generic.c index 34ed94007e..d27c7a867f 100644 --- a/arch/arm/mach-omap/omap_generic.c +++ b/arch/arm/mach-omap/omap_generic.c @@ -130,7 +130,7 @@ static int omap_env_init(void) device_detect_by_name(diskdev); - partname = asprintf("/dev/%s.0", diskdev); + partname = basprintf("/dev/%s.0", diskdev); mkdir("/boot", 0666); ret = mount(partname, "fat", "/boot", NULL); diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c index 8805930215..77938190e1 100644 --- a/arch/arm/mach-omap/xload.c +++ b/arch/arm/mach-omap/xload.c @@ -115,7 +115,7 @@ static void *omap_xload_boot_mmc(void) device_detect_by_name(diskdev); - partname = asprintf("%s.0", diskdev); + partname = basprintf("%s.0", diskdev); ret = mount(partname, NULL, "/", NULL); @@ -280,7 +280,7 @@ static void *am33xx_net_boot(void) return NULL; } - file = asprintf("%s/%s", TFTP_MOUNT, bootfile); + file = basprintf("%s/%s", TFTP_MOUNT, bootfile); buf = read_file(file, &len); if (!buf) diff --git a/commands/boot.c b/commands/boot.c index f403010130..bd1be4ba75 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -156,7 +156,7 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path) return 1; } - files = asprintf("%s/*", path); + files = basprintf("%s/*", path); glob(files, 0, NULL, &globb); @@ -208,7 +208,7 @@ static int bootentry_parse_one(struct blspec *blspec, const char *name) char *path; if (*name != '/') - path = asprintf("/env/boot/%s", name); + path = basprintf("/env/boot/%s", name); else path = xstrdup(name); @@ -233,7 +233,7 @@ static struct blspec *bootentries_collect(char *entries[], int num_entries) blspec = blspec_alloc(); if (IS_ENABLED(CONFIG_MENU)) - blspec->menu->display = asprintf("boot"); + blspec->menu->display = basprintf("boot"); if (!num_entries) bootscript_scan_path(blspec, "/env/boot"); diff --git a/commands/clk.c b/commands/clk.c index e9459a3fd3..65832d4985 100644 --- a/commands/clk.c +++ b/commands/clk.c @@ -110,7 +110,7 @@ static int do_clk_get_rate(int argc, char *argv[]) if (variable_name) { char *t; - t = asprintf("%lu", rate); + t = basprintf("%lu", rate); setenv(variable_name, t); free(t); } else diff --git a/commands/crc.c b/commands/crc.c index 066d91e179..edb1fb125c 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -98,13 +98,13 @@ static int do_crc(int argc, char *argv[]) filename, (ulong)start, (ulong)start + total - 1, crc); if (crcvarname) { - char *crcstr = asprintf("0x%lx", crc); + char *crcstr = basprintf("0x%lx", crc); setenv(crcvarname, crcstr); kfree(crcstr); } if (sizevarname) { - char *sizestr = asprintf("0x%lx", total); + char *sizestr = basprintf("0x%lx", total); setenv(sizevarname, sizestr); kfree(sizestr); } diff --git a/commands/defaultenv.c b/commands/defaultenv.c index bae2d78f47..47bdf26d14 100644 --- a/commands/defaultenv.c +++ b/commands/defaultenv.c @@ -60,8 +60,8 @@ static int do_defaultenv(int argc, char *argv[]) if (ret) return ret; - from = asprintf("/.defaultenv/%s", restorepath); - to = asprintf("%s/%s", dirname, restorepath); + from = basprintf("/.defaultenv/%s", restorepath); + to = basprintf("%s/%s", dirname, restorepath); printf("Restoring %s from default environment\n", restorepath); diff --git a/commands/hashsum.c b/commands/hashsum.c index 8d3694fa78..d05e571fb9 100644 --- a/commands/hashsum.c +++ b/commands/hashsum.c @@ -46,7 +46,7 @@ static int do_hash(char *algo, int argc, char *argv[]) } if (key) { - char *tmp = asprintf("hmac(%s)", algo); + char *tmp = basprintf("hmac(%s)", algo); d = digest_alloc(tmp); free(tmp); BUG_ON(!d); diff --git a/commands/tftp.c b/commands/tftp.c index 8a3b541382..6a3121ad56 100644 --- a/commands/tftp.c +++ b/commands/tftp.c @@ -58,10 +58,10 @@ static int do_tftpb(int argc, char *argv[]) dest = argv[optind]; if (tftp_push) { - dest = freep = asprintf("%s/%s", TFTP_MOUNT_PATH, dest); + dest = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, dest); flags = O_RDONLY; } else { - source = freep = asprintf("%s/%s", TFTP_MOUNT_PATH, source); + source = freep = basprintf("%s/%s", TFTP_MOUNT_PATH, source); flags = O_WRONLY | O_CREAT; } diff --git a/common/blspec.c b/common/blspec.c index 18005569ff..b92f49fa2b 100644 --- a/common/blspec.c +++ b/common/blspec.c @@ -203,16 +203,18 @@ static char *parse_nfs_url(const char *url) if (ip == 0) goto out; - hostpath = asprintf("%s:%s", ip_to_string(ip), path); + hostpath = basprintf("%s:%s", ip_to_string(ip), path); prevpath = nfs_find_mountpath(hostpath); if (prevpath) { mountpath = xstrdup(prevpath); } else { - mountpath = asprintf("/mnt/nfs-%s-blspec-%08x", host, rand()); + mountpath = basprintf("/mnt/nfs-%s-blspec-%08x", host, + rand()); if (port) - options = asprintf("mountport=%s,port=%s", port, port); + options = basprintf("mountport=%s,port=%s", port, + port); ret = make_directory(mountpath); if (ret) @@ -278,7 +280,7 @@ static bool entry_is_of_compatible(struct blspec_entry *entry) if (!strcmp(devicetree, "none")) return true; - filename = asprintf("%s/%s", abspath, devicetree); + filename = basprintf("%s/%s", abspath, devicetree); fdt = read_file(filename, &size); if (!fdt) { @@ -338,7 +340,7 @@ int blspec_scan_directory(struct blspec *blspec, const char *root) entry_default = read_file_line("%s/default", root); entry_once = read_file_line("%s/once", root); - abspath = asprintf("%s/%s", root, dirname); + abspath = basprintf("%s/%s", root, dirname); dir = opendir(abspath); if (!dir) { @@ -356,7 +358,7 @@ int blspec_scan_directory(struct blspec *blspec, const char *root) if (*d->d_name == '.') continue; - configname = asprintf("%s/%s", abspath, d->d_name); + configname = basprintf("%s/%s", abspath, d->d_name); dot = strrchr(configname, '.'); if (!dot) { @@ -402,7 +404,7 @@ int blspec_scan_directory(struct blspec *blspec, const char *root) found++; - name = asprintf("%s/%s", dirname, d->d_name); + name = basprintf("%s/%s", dirname, d->d_name); if (entry_default && !strcmp(name, entry_default)) entry->boot_default = true; if (entry_once && !strcmp(name, entry_once)) @@ -415,10 +417,10 @@ int blspec_scan_directory(struct blspec *blspec, const char *root) hwdevname = xstrdup(dev_name(entry->cdev->dev->parent)); } - entry->me.display = asprintf("%-20s %-20s %s", - devname ? devname : "", - hwdevname ? hwdevname : "", - blspec_entry_var_get(entry, "title")); + entry->me.display = basprintf("%-20s %-20s %s", + devname ? devname : "", + hwdevname ? hwdevname : "", + blspec_entry_var_get(entry, "title")); free(devname); free(hwdevname); @@ -691,7 +693,7 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun) else abspath = ""; - data.os_file = asprintf("%s/%s", abspath, linuximage); + data.os_file = basprintf("%s/%s", abspath, linuximage); if (devicetree) { if (!strcmp(devicetree, "none")) { @@ -699,13 +701,13 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun) if (node) of_delete_node(node); } else { - data.oftree_file = asprintf("%s/%s", abspath, - devicetree); + data.oftree_file = basprintf("%s/%s", abspath, + devicetree); } } if (initrd) - data.initrd_file = asprintf("%s/%s", abspath, initrd); + data.initrd_file = basprintf("%s/%s", abspath, initrd); globalvar_add_simple("linux.bootargs.dyn.blspec", options); @@ -717,7 +719,7 @@ int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun) entry->cdev ? dev_name(entry->cdev->dev) : "none"); if (entry->boot_once) { - char *s = asprintf("%s/once", abspath); + char *s = basprintf("%s/once", abspath); ret = unlink(s); if (ret) diff --git a/common/bootargs.c b/common/bootargs.c index 803736fc94..a89f23a3f2 100644 --- a/common/bootargs.c +++ b/common/bootargs.c @@ -53,7 +53,8 @@ const char *linux_bootargs_get(void) parts = globalvar_get_match("linux.mtdparts.", ";"); if (strlen(parts)) { - bootargs = asprintf("%s mtdparts=%s", linux_bootargs, parts); + bootargs = basprintf("%s mtdparts=%s", linux_bootargs, + parts); free(linux_bootargs); free(parts); linux_bootargs = bootargs; @@ -61,7 +62,8 @@ const char *linux_bootargs_get(void) parts = globalvar_get_match("linux.blkdevparts.", ";"); if (strlen(parts)) { - bootargs = asprintf("%s blkdevparts=%s", linux_bootargs, parts); + bootargs = basprintf("%s blkdevparts=%s", linux_bootargs, + parts); free(linux_bootargs); free(parts); linux_bootargs = bootargs; diff --git a/common/console.c b/common/console.c index a541892583..f0988b8bc0 100644 --- a/common/console.c +++ b/common/console.c @@ -208,8 +208,8 @@ static void console_set_stdoutpath(struct console_device *cdev) if (id < 0) return; - str = asprintf("console=%s%d,%dn8", cdev->linux_console_name, - id, cdev->baudrate); + str = basprintf("console=%s%d,%dn8", cdev->linux_console_name, id, + cdev->baudrate); globalvar_add_simple("linux.bootargs.console", str); diff --git a/common/env.c b/common/env.c index c98ed73f9b..5f63e2dd27 100644 --- a/common/env.c +++ b/common/env.c @@ -260,7 +260,7 @@ EXPORT_SYMBOL(export); void export_env_ull(const char *name, unsigned long long val) { - char *valstr = asprintf("%llu", val); + char *valstr = basprintf("%llu", val); setenv(name, valstr); export(name); diff --git a/common/environment.c b/common/environment.c index 65404afa14..fa6b59620e 100644 --- a/common/environment.c +++ b/common/environment.c @@ -80,7 +80,7 @@ static int do_compare_file(const char *filename, const char *base) char *cmp; const char *relname = filename + strlen(base) + 1; - cmp = asprintf("%s/%s", TMPDIR, relname); + cmp = basprintf("%s/%s", TMPDIR, relname); ret = compare_file(cmp, filename); free(cmp); @@ -193,7 +193,7 @@ static int file_remove_action(const char *filename, struct stat *statbuf, filename += sizeof(TMPDIR) - 1; - envname = asprintf("%s/%s", data->base, filename); + envname = basprintf("%s/%s", data->base, filename); ret = stat(envname, &s); if (ret) { diff --git a/common/firmware.c b/common/firmware.c index a6f75bf887..664f9107d0 100644 --- a/common/firmware.c +++ b/common/firmware.c @@ -202,7 +202,7 @@ out: int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) { int ret; - char *name = asprintf("/dev/%s", mgr->handler->id); + char *name = basprintf("/dev/%s", mgr->handler->id); ret = copy_file(firmware, name, 0); diff --git a/common/globalvar.c b/common/globalvar.c index 9a793ac4a9..d5dd461963 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -42,7 +42,7 @@ static int nv_save(const char *name, const char *val) if (ret) return ret; - fname = asprintf("/env/nv/%s", name); + fname = basprintf("/env/nv/%s", name); fd = open(fname, O_CREAT | O_WRONLY | O_TRUNC); @@ -135,7 +135,7 @@ int nvvar_remove(const char *name) if (!p) return -ENOENT; - fname = asprintf("/env/nv/%s", p->name); + fname = basprintf("/env/nv/%s", p->name); unlink(fname); free(fname); @@ -217,7 +217,8 @@ char *globalvar_get_match(const char *match, const char *separator) if (!strncmp(match, param->name, strlen(match))) { const char *p = dev_get_param(&global_device, param->name); if (val) { - char *new = asprintf("%s%s%s", val, separator, p); + char *new = basprintf("%s%s%s", val, + separator, p); free(val); val = new; } else { diff --git a/common/menutree.c b/common/menutree.c index 1505ec8541..eb14da0d01 100644 --- a/common/menutree.c +++ b/common/menutree.c @@ -98,7 +98,7 @@ int menutree(const char *path, int toplevel) menu = menu_alloc(); - globpath = asprintf("%s/*", path); + globpath = basprintf("%s/*", path); ret = glob(globpath, 0, NULL, &g); free(globpath); if (ret == GLOB_NOMATCH) { @@ -149,7 +149,7 @@ int menutree(const char *path, int toplevel) mt->me.type = MENU_ENTRY_NORMAL; - mt->action = asprintf("%s/action", g.gl_pathv[i]); + mt->action = basprintf("%s/action", g.gl_pathv[i]); ret = stat(mt->action, &s); if (ret) { diff --git a/common/partitions.c b/common/partitions.c index 82ec508e64..69a2b1fefb 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -51,7 +51,7 @@ static int register_one_partition(struct block_device *blk, uint64_t size = part->size * SECTOR_SIZE; struct cdev *cdev; - partition_name = asprintf("%s.%d", blk->cdev.name, no); + partition_name = basprintf("%s.%d", blk->cdev.name, no); if (!partition_name) return -ENOMEM; dev_dbg(blk->dev, "Registering partition %s on drive %s\n", diff --git a/common/state.c b/common/state.c index c763ca4a41..87afff3056 100644 --- a/common/state.c +++ b/common/state.c @@ -704,8 +704,8 @@ static int state_convert_node_variable(struct state *state, *indexs = 0; /* construct full name */ - name = asprintf("%s%s%s", - parent_name, parent_name[0] ? "." : "", short_name); + name = basprintf("%s%s%s", parent_name, parent_name[0] ? "." : "", + short_name); free(short_name); if ((conv == STATE_CONVERT_TO_NODE) || diff --git a/crypto/hmac.c b/crypto/hmac.c index 20af2a56de..05b9b50f12 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -173,8 +173,8 @@ static int digest_hmac_register(char *name, unsigned int pad_length) dh->name = xstrdup(name); dh->pad_length = pad_length; dh->algo = hmac_algo; - dh->algo.base.name = asprintf("hmac(%s)", name); - dh->algo.base.driver_name = asprintf("hmac(%s)-generic", name); + dh->algo.base.name = basprintf("hmac(%s)", name); + dh->algo.base.driver_name = basprintf("hmac(%s)-generic", name); return digest_algo_register(&dh->algo); } diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c index d30d0ad997..cd46e0cf6a 100644 --- a/drivers/ata/disk_ata_drive.c +++ b/drivers/ata/disk_ata_drive.c @@ -243,7 +243,7 @@ static int ata_port_init(struct ata_port *port) rc = cdev_find_free_index("ata"); if (rc == -1) pr_err("Cannot find a free index for the disk node\n"); - port->blk.cdev.name = asprintf("ata%d", rc); + port->blk.cdev.name = basprintf("ata%d", rc); } port->blk.num_blocks = ata_id_n_sectors(port->id); diff --git a/drivers/ata/disk_bios_drive.c b/drivers/ata/disk_bios_drive.c index 8e768dc7f2..363af3c6dd 100644 --- a/drivers/ata/disk_bios_drive.c +++ b/drivers/ata/disk_bios_drive.c @@ -258,7 +258,7 @@ static int biosdisk_probe(struct device_d *dev) rc = cdev_find_free_index("disk"); if (rc < 0) pr_err("Cannot find a free number for the disk node\n"); - m->blk.cdev.name = asprintf("disk%d", rc); + m->blk.cdev.name = basprintf("disk%d", rc); m->blk.blockbits = SECTOR_SHIFT; rc = blockdevice_register(&m->blk); diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c index 3c0a7a9d47..a323d25dd4 100644 --- a/drivers/eeprom/at24.c +++ b/drivers/eeprom/at24.c @@ -429,7 +429,7 @@ static int at24_probe(struct device_d *dev) at24->chip = chip; at24->num_addresses = num_addresses; - at24->cdev.name = asprintf("eeprom%d", dev->id); + at24->cdev.name = basprintf("eeprom%d", dev->id); at24->cdev.priv = at24; at24->cdev.dev = dev; at24->cdev.ops = &at24->fops; diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index 24f57f9da9..59f66757d9 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -506,8 +506,8 @@ static int mmc_change_freq(struct mci *mci) char *name, *partname; part_size = mci->ext_csd[EXT_CSD_BOOT_MULT] << 17; - partname = asprintf("boot%d", idx); - name = asprintf("%s.%s", mci->cdevname, partname); + partname = basprintf("boot%d", idx); + name = basprintf("%s.%s", mci->cdevname, partname); mci_part_add(mci, part_size, EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, name, partname, idx, true, @@ -1626,7 +1626,7 @@ static int mci_card_probe(struct mci *mci) mci->cdevname = strdup(host->devname); } else { disknum = cdev_find_free_index("disk"); - mci->cdevname = asprintf("disk%d", disknum); + mci->cdevname = basprintf("disk%d", disknum); } rc = mci_startup(mci); diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c index c1e7d9ece4..fb91ffa008 100644 --- a/drivers/mfd/stmpe-i2c.c +++ b/drivers/mfd/stmpe-i2c.c @@ -141,8 +141,8 @@ static int stmpe_probe(struct device_d *dev) } stmpe_dev = xzalloc(sizeof(struct stmpe)); - stmpe_dev->cdev.name = asprintf(DRIVERNAME "%d", - cdev_find_free_index(DRIVERNAME)); + stmpe_dev->cdev.name = basprintf(DRIVERNAME"%d", + cdev_find_free_index(DRIVERNAME)); stmpe_dev->client = to_i2c_client(dev); stmpe_dev->cdev.size = 191; /* 191 known registers */ stmpe_dev->cdev.dev = dev; diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index 58b574157a..4fb6f801d2 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -47,8 +47,7 @@ static int sram_probe(struct device_d *dev) sram = xzalloc(sizeof(*sram)); - sram->cdev.name = asprintf("sram%d", - cdev_find_free_index("sram")); + sram->cdev.name = basprintf("sram%d", cdev_find_free_index("sram")); res = dev_get_resource(dev, IORESOURCE_MEM, 0); if (IS_ERR(res)) diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index dcf94bfc0d..6d04b88553 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -470,10 +470,10 @@ static int mtd_partition_set(struct device_d *dev, struct param_d *p, const char static char *print_size(uint64_t s) { if (!(s & ((1 << 20) - 1))) - return asprintf("%lldM", s >> 20); + return basprintf("%lldM", s >> 20); if (!(s & ((1 << 10) - 1))) - return asprintf("%lldk", s >> 10); - return asprintf("0x%lld", s); + return basprintf("%lldk", s >> 10); + return basprintf("0x%lld", s); } static int print_part(char *buf, int bufsize, struct mtd_info *mtd, uint64_t last_ofs, @@ -577,7 +577,8 @@ static int of_mtd_fixup(struct device_node *root, void *ctx) list_for_each_entry(partmtd, &mtd->partitions, partitions_entry) { int na, ns, len = 0; - char *name = asprintf("partition@%0llx", partmtd->master_offset); + char *name = basprintf("partition@%0llx", + partmtd->master_offset); void *p; u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */ @@ -675,7 +676,8 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id) if (device_id == DEVICE_ID_SINGLE) mtd->cdev.name = xstrdup(devname); else - mtd->cdev.name = asprintf("%s%d", devname, mtd->class_dev.id); + mtd->cdev.name = basprintf("%s%d", devname, + mtd->class_dev.id); INIT_LIST_HEAD(&mtd->partitions); diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 6a9bc74847..a40ba25632 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1058,8 +1058,8 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) switch (chip_id) { case DOC_CHIPID_G3: - mtd->name = asprintf("DiskOnChip G3 floor %d", - docg3->device_id); + mtd->name = basprintf("DiskOnChip G3 floor %d", + docg3->device_id); docg3->max_block = 2047; break; } diff --git a/drivers/mtd/mtdoob.c b/drivers/mtd/mtdoob.c index 4dcf2f5915..86076f028d 100644 --- a/drivers/mtd/mtdoob.c +++ b/drivers/mtd/mtdoob.c @@ -79,7 +79,7 @@ static int add_mtdoob_device(struct mtd_info *mtd, const char *devname, void **p mtdoob = xzalloc(sizeof(*mtdoob)); mtdoob->cdev.ops = &mtd_ops_oob; mtdoob->cdev.size = mtd_div_by_wb(mtd->size, mtd) * mtd->oobsize; - mtdoob->cdev.name = asprintf("%s.oob", mtd->cdev.name); + mtdoob->cdev.name = basprintf("%s.oob", mtd->cdev.name); mtdoob->cdev.priv = mtdoob; mtdoob->cdev.dev = &mtd->class_dev; mtdoob->mtd = mtd; diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c index 4d6ac72bd9..b06eb18f3f 100644 --- a/drivers/mtd/mtdraw.c +++ b/drivers/mtd/mtdraw.c @@ -308,7 +308,7 @@ static int add_mtdraw_device(struct mtd_info *mtd, const char *devname, void **p mtdraw->cdev.ops = (struct file_operations *)&mtd_raw_fops; mtdraw->cdev.size = mtd_div_by_wb(mtd->size, mtd) * (mtd->writesize + mtd->oobsize); - mtdraw->cdev.name = asprintf("%s.raw", mtd->cdev.name); + mtdraw->cdev.name = basprintf("%s.raw", mtd->cdev.name); mtdraw->cdev.priv = mtdraw; mtdraw->cdev.dev = &mtd->class_dev; mtdraw->cdev.mtd = mtd; diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c index e6d42772b3..015f8dc524 100644 --- a/drivers/mtd/nand/nand-bb.c +++ b/drivers/mtd/nand/nand-bb.c @@ -288,7 +288,7 @@ struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name) if (name) bb->cdev.name = xstrdup(name); else - bb->cdev.name = asprintf("%s.bb", mtd->cdev.name); + bb->cdev.name = basprintf("%s.bb", mtd->cdev.name); nand_bb_calc_size(bb); bb->cdev.ops = &nand_bb_ops; diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c index c26a2455b2..ad38e69ea5 100644 --- a/drivers/mtd/ubi/barebox.c +++ b/drivers/mtd/ubi/barebox.c @@ -176,7 +176,7 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol) priv->ubi = ubi; cdev->ops = &ubi_volume_fops; - cdev->name = asprintf("%s.%s", ubi->cdev.name, vol->name); + cdev->name = basprintf("%s.%s", ubi->cdev.name, vol->name); cdev->priv = priv; cdev->size = vol->used_bytes; cdev->dev = &vol->dev; @@ -239,7 +239,7 @@ int ubi_cdev_add(struct ubi_device *ubi) int ret; cdev->ops = &ubi_fops; - cdev->name = asprintf("%s.ubi", ubi->mtd->cdev.name); + cdev->name = basprintf("%s.ubi", ubi->mtd->cdev.name); cdev->priv = ubi; cdev->size = 0; diff --git a/drivers/net/ksz8864rmn.c b/drivers/net/ksz8864rmn.c index 3ca85fb3f3..860af448ea 100644 --- a/drivers/net/ksz8864rmn.c +++ b/drivers/net/ksz8864rmn.c @@ -149,7 +149,7 @@ static int micrel_switch_probe(struct device_d *dev) return -ENODEV; } - priv->cdev.name = asprintf("switch%d", dev->id); + priv->cdev.name = basprintf("switch%d", dev->id); priv->cdev.size = 256; priv->cdev.ops = &micrel_switch_ops; priv->cdev.priv = priv; diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c index 125feef2cc..64f483326d 100644 --- a/drivers/of/barebox.c +++ b/drivers/of/barebox.c @@ -61,7 +61,7 @@ static int environment_check_mount(struct device_d *dev, char **devpath) /* Set env to be in a file on the now mounted device */ dev_dbg(dev, "Loading default env from %s on device %s\n", filepath, *devpath); - *devpath = asprintf("%s/%s", ENV_MNT_DIR, filepath); + *devpath = basprintf("%s/%s", ENV_MNT_DIR, filepath); return 0; } diff --git a/drivers/of/base.c b/drivers/of/base.c index d12bfe328a..b4ef8e362f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1702,7 +1702,8 @@ struct device_node *of_new_node(struct device_node *parent, const char *name) if (parent) { node->name = xstrdup(name); - node->full_name = asprintf("%s/%s", node->parent->full_name, name); + node->full_name = basprintf("%s/%s", + node->parent->full_name, name); list_add(&node->list, &parent->list); } else { node->name = xstrdup(""); diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c index ed620f1755..8e1931f939 100644 --- a/drivers/of/of_path.c +++ b/drivers/of/of_path.c @@ -75,7 +75,7 @@ static int __of_find_path(struct device_node *node, const char *part, char **out mtd_can_have_bb(cdev->mtd)) add_bb = true; - *outpath = asprintf("/dev/%s%s", cdev->name, add_bb ? ".bb" : ""); + *outpath = basprintf("/dev/%s%s", cdev->name, add_bb ? ".bb" : ""); return 0; } diff --git a/drivers/of/partition.c b/drivers/of/partition.c index 6017897b02..b6621f7dad 100644 --- a/drivers/of/partition.c +++ b/drivers/of/partition.c @@ -58,7 +58,7 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node) if (of_get_property(node, "read-only", &len)) flags = DEVFS_PARTITION_READONLY; - filename = asprintf("%s.%s", cdev->name, partname); + filename = basprintf("%s.%s", cdev->name, partname); new = devfs_add_partition(cdev->name, offset, size, flags, filename); if (IS_ERR(new)) diff --git a/drivers/pci/pci-mvebu.c b/drivers/pci/pci-mvebu.c index da2459bafe..907bda0f96 100644 --- a/drivers/pci/pci-mvebu.c +++ b/drivers/pci/pci-mvebu.c @@ -306,7 +306,7 @@ static struct mvebu_pcie *mvebu_pcie_port_probe(struct device_d *dev, reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &flags); if (gpio_is_valid(reset_gpio)) { int reset_active_low = flags & OF_GPIO_ACTIVE_LOW; - char *reset_name = asprintf("pcie%d.%d-reset", port, lane); + char *reset_name = basprintf("pcie%d.%d-reset", port, lane); u32 reset_udelay = 20000; of_property_read_u32(np, "reset-delay-us", &reset_udelay); @@ -326,7 +326,7 @@ static struct mvebu_pcie *mvebu_pcie_port_probe(struct device_d *dev, pcie->port = port; pcie->lane = lane; pcie->lane_mask = lane_mask; - pcie->name = asprintf("pcie%d.%d", port, lane); + pcie->name = basprintf("pcie%d.%d", port, lane); pcie->devfn = devfn; pcie->base = of_iomap(np, 0); diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c index 10ce186a12..e7b08a2bfe 100644 --- a/drivers/pinctrl/pinctrl.c +++ b/drivers/pinctrl/pinctrl.c @@ -68,7 +68,7 @@ int of_pinctrl_select_state(struct device_node *np, const char *name) /* For each defined state ID */ for (state = 0; ; state++) { /* Retrieve the pinctrl-* property */ - propname = asprintf("pinctrl-%d", state); + propname = basprintf("pinctrl-%d", state); prop = of_find_property(np, propname, NULL); free(propname); diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index 0845c234fe..b620e502f2 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -236,9 +236,10 @@ static int imx_pwm_probe(struct device_d *dev) if (dev->device_node) { imx->chip.devname = of_alias_get(dev->device_node); if (!imx->chip.devname) - imx->chip.devname = asprintf("pwm_%p", imx->mmio_base); + imx->chip.devname = basprintf("pwm_%p", + imx->mmio_base); } else { - imx->chip.devname = asprintf("pwm%d", dev->id); + imx->chip.devname = basprintf("pwm%d", dev->id); } imx->config = data->config; diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index 011d9002ba..e72f1dbcb0 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -143,7 +143,7 @@ static int mxs_pwm_probe(struct device_d *dev) struct mxs_pwm_chip *mxspwm = &mxs->pwm[i]; mxspwm->chip.ops = &mxs_pwm_ops; - mxspwm->chip.devname = asprintf("pwm%d", i); + mxspwm->chip.devname = basprintf("pwm%d", i); mxspwm->chip.id = i; mxspwm->mxs = mxs; diff --git a/drivers/pwm/pxa_pwm.c b/drivers/pwm/pxa_pwm.c index e399d03efd..c7130c225e 100644 --- a/drivers/pwm/pxa_pwm.c +++ b/drivers/pwm/pxa_pwm.c @@ -134,7 +134,7 @@ static int pxa_pwm_probe(struct device_d *dev) struct pxa_pwm_chip *chip; chip = xzalloc(sizeof(*chip)); - chip->chip.devname = asprintf("pwm%d", dev->id); + chip->chip.devname = basprintf("pwm%d", dev->id); chip->chip.ops = &pxa_pwm_ops; iores = dev_request_mem_resource(dev, 0); if (IS_ERR(iores)) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 73f5c6eb4b..39df980dcb 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -153,7 +153,7 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c struct regulator_internal *ri; struct device_node *node; - propname = asprintf("%s-supply", supply); + propname = basprintf("%s-supply", supply); /* * If the device does have a device node return the dummy regulator. diff --git a/drivers/spi/gpio_spi.c b/drivers/spi/gpio_spi.c index 4ea545a282..e37db756f8 100644 --- a/drivers/spi/gpio_spi.c +++ b/drivers/spi/gpio_spi.c @@ -209,7 +209,7 @@ static int gpio_spi_probe(struct device_d *dev) if (!gpio_is_valid(pdata->cs[n])) continue; - cs_name = asprintf("spi-cs%d", n); + cs_name = basprintf("spi-cs%d", n); ret = gpio_request_one(pdata->cs[n], GPIOF_DIR_OUT, cs_name); if (ret) return ret; diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index ba3b9da206..9e38ac4942 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1763,7 +1763,7 @@ EXPORT_SYMBOL_GPL(usb_composite_setup_continue); static char *composite_default_mfr(struct usb_gadget *gadget) { - return asprintf("barebox %s", gadget->name); + return basprintf("barebox %s", gadget->name); } void usb_composite_overwrite_options(struct usb_composite_dev *cdev, diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 9a8cd4c844..fdea52eb93 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -195,7 +195,7 @@ static void fb_setvar(struct fb_variable *var, const char *fmt, ...) va_list ap; va_start(ap, fmt); - var->value = vasprintf(fmt, ap); + var->value = bvasprintf(fmt, ap); va_end(ap); } @@ -205,7 +205,7 @@ static struct fb_variable *fb_addvar(struct f_fastboot *f_fb, const char *fmt, . va_list ap; va_start(ap, fmt); - var->name = vasprintf(fmt, ap); + var->name = bvasprintf(fmt, ap); va_end(ap); list_add_tail(&var->list, &f_fb->variables); @@ -702,7 +702,8 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req, const char *cmd if (ret) goto copy; - cmd = asprintf("ubiformat -y -f %s %s", FASTBOOT_TMPFILE, filename); + cmd = basprintf("ubiformat -y -f %s %s", FASTBOOT_TMPFILE, + filename); fastboot_tx_print(f_fb, "INFOThis is an UBI image..."); diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 9d1ffa3070..8218bb2a71 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c @@ -397,7 +397,7 @@ static int usb_stor_add_blkdev(struct us_data *us, struct device_d *dev, pr_err("Cannot find a free number for the disk node\n"); pr_info("Using index %d for the new disk\n", result); - pblk_dev->blk.cdev.name = asprintf("disk%d", result); + pblk_dev->blk.cdev.name = basprintf("disk%d", result); pblk_dev->blk.blockbits = SECTOR_SHIFT; result = blockdevice_register(&pblk_dev->blk); diff --git a/drivers/video/edid.c b/drivers/video/edid.c index 828c3610ac..e5c32a0c1b 100644 --- a/drivers/video/edid.c +++ b/drivers/video/edid.c @@ -469,7 +469,8 @@ static void calc_mode_timings(int xres, int yres, int refresh, mode->yres = yres; mode->refresh = refresh; fb_get_mode(0, refresh, mode); - mode->name = asprintf("%dx%d@%d-calc", mode->xres, mode->yres, mode->refresh); + mode->name = basprintf("%dx%d@%d-calc", mode->xres, mode->yres, + mode->refresh); pr_debug(" %s\n", mode->name); } @@ -602,7 +603,8 @@ const struct fb_videomode vesa_modes[] = { static void add_vesa_mode(struct fb_videomode *mode, int num) { *mode = vesa_modes[num]; - mode->name = asprintf("%dx%d@%d-vesa", mode->xres, mode->yres, mode->refresh); + mode->name = basprintf("%dx%d@%d-vesa", mode->xres, mode->yres, + mode->refresh); pr_debug(" %s\n", mode->name); } @@ -748,7 +750,8 @@ static void get_detailed_timing(unsigned char *block, pr_debug("%sHSync %sVSync\n", (HSYNC_POSITIVE) ? "+" : "-", (VSYNC_POSITIVE) ? "+" : "-"); - mode->name = asprintf("%dx%d@%d", mode->xres, mode->yres, mode->refresh); + mode->name = basprintf("%dx%d@%d", mode->xres, mode->yres, + mode->refresh); } /** diff --git a/drivers/video/fb.c b/drivers/video/fb.c index 09bba001fb..4d2d3aa650 100644 --- a/drivers/video/fb.c +++ b/drivers/video/fb.c @@ -262,7 +262,7 @@ int register_framebuffer(struct fb_info *info) info->line_length = info->xres * (info->bits_per_pixel >> 3); info->cdev.ops = &fb_ops; - info->cdev.name = asprintf("fb%d", id); + info->cdev.name = basprintf("fb%d", id); info->cdev.size = info->line_length * info->yres; info->cdev.dev = dev; info->cdev.priv = info; diff --git a/drivers/video/imx-ipu-v3/imx-ldb.c b/drivers/video/imx-ipu-v3/imx-ldb.c index 2340b9b1d6..17ae894bf7 100644 --- a/drivers/video/imx-ipu-v3/imx-ldb.c +++ b/drivers/video/imx-ipu-v3/imx-ldb.c @@ -161,7 +161,7 @@ static int imx6q_ldb_prepare(struct imx_ldb_channel *imx_ldb_ch, int di, ipuno = ((di >> 1) & 1) + 1; dino = di & 0x1; - clkname = asprintf("ipu%d_di%d_sel", ipuno, dino); + clkname = basprintf("ipu%d_di%d_sel", ipuno, dino); diclk = clk_lookup(clkname); free(clkname); if (IS_ERR(diclk)) { @@ -169,7 +169,7 @@ static int imx6q_ldb_prepare(struct imx_ldb_channel *imx_ldb_ch, int di, return PTR_ERR(diclk); } - clkname = asprintf("ldb_di%d_podf", imx_ldb_ch->chno); + clkname = basprintf("ldb_di%d_podf", imx_ldb_ch->chno); ldbclk = clk_lookup(clkname); free(clkname); if (IS_ERR(ldbclk)) { @@ -208,7 +208,7 @@ static int imx53_ldb_prepare(struct imx_ldb_channel *imx_ldb_ch, int di, dino = di & 0x1; - clkname = asprintf("ipu_di%d_sel", dino); + clkname = basprintf("ipu_di%d_sel", dino); diclk = clk_lookup(clkname); free(clkname); if (IS_ERR(diclk)) { @@ -216,7 +216,7 @@ static int imx53_ldb_prepare(struct imx_ldb_channel *imx_ldb_ch, int di, return PTR_ERR(diclk); } - clkname = asprintf("ldb_di%d_div", imx_ldb_ch->chno); + clkname = basprintf("ldb_di%d_div", imx_ldb_ch->chno); ldbclk = clk_lookup(clkname); free(clkname); if (IS_ERR(ldbclk)) { diff --git a/drivers/video/imx-ipu-v3/ipu-di.c b/drivers/video/imx-ipu-v3/ipu-di.c index 8df9c9f06b..b6e64fe16a 100644 --- a/drivers/video/imx-ipu-v3/ipu-di.c +++ b/drivers/video/imx-ipu-v3/ipu-di.c @@ -732,8 +732,7 @@ int ipu_di_init(struct ipu_soc *ipu, struct device_d *dev, int id, ipu_di_write(di, 0x10, DI_BS_CLKGEN0); di->clk_di_pixel.parent_names = di->di_parent_names; - di->clk_name = asprintf("%s_di%d_pixel", - dev_name(dev), id); + di->clk_name = basprintf("%s_di%d_pixel", dev_name(dev), id); if (!di->clk_name) return -ENOMEM; diff --git a/drivers/video/imx-ipu-v3/ipufb.c b/drivers/video/imx-ipu-v3/ipufb.c index 747e094789..67fec11d4a 100644 --- a/drivers/video/imx-ipu-v3/ipufb.c +++ b/drivers/video/imx-ipu-v3/ipufb.c @@ -284,7 +284,7 @@ static int ipufb_probe(struct device_d *dev) info = &fbi->info; ipuid = of_alias_get_id(dev->parent->device_node, "ipu"); - fbi->name = asprintf("ipu%d-di%d", ipuid + 1, pdata->di); + fbi->name = basprintf("ipu%d-di%d", ipuid + 1, pdata->di); fbi->id = ipuid * 2 + pdata->di; fbi->dino = pdata->di; diff --git a/drivers/w1/slaves/w1_ds2431.c b/drivers/w1/slaves/w1_ds2431.c index 30e6e1d496..e3e929670d 100644 --- a/drivers/w1/slaves/w1_ds2431.c +++ b/drivers/w1/slaves/w1_ds2431.c @@ -272,7 +272,7 @@ static int ds2431_probe(struct w1_device *dev) cdev->priv = dev; cdev->ops = &ds2431_ops; cdev->size = W1_F2D_EEPROM_SIZE; - cdev->name = asprintf(DRIVERNAME"%d", ds2431_count++); + cdev->name = basprintf(DRIVERNAME"%d", ds2431_count++); if (cdev->name == NULL) return -ENOMEM; diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index a840d9a2f2..a907c6bf3c 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -171,7 +171,7 @@ static int ds2433_cdev_create(struct w1_device *dev, int size, int id) cdev->priv = dev; cdev->ops = &ds2433_ops; cdev->size = size; - cdev->name = asprintf("%s%d", dev->dev.driver->name, id); + cdev->name = basprintf("%s%d", dev->dev.driver->name, id); if (cdev->name == NULL) return -ENOMEM; diff --git a/fs/bpkfs.c b/fs/bpkfs.c index 309a122c19..f1db963d09 100644 --- a/fs/bpkfs.c +++ b/fs/bpkfs.c @@ -103,7 +103,7 @@ static struct bpkfs_handle_hw *bpkfs_get_or_add_hw_id( INIT_LIST_HEAD(&h->list_data); h->hw_id = hw_id; - h->name = asprintf("hw_id_%x", hw_id); + h->name = basprintf("hw_id_%x", hw_id); list_add_tail(&h->list_hw_id, &handle->list); return h; @@ -431,7 +431,7 @@ static int bpkfs_probe(struct device_d *dev) if (!type) { type = "unknown"; - d->name = asprintf("%s_%08x", type, d->type); + d->name = basprintf("%s_%08x", type, d->type); } else { d->name = xstrdup(type); } @@ -464,7 +464,7 @@ static int bpkfs_probe(struct device_d *dev) type = d->name; d = xzalloc(sizeof(*d)); d->type = be32_to_cpu(data_header.type); - d->name = asprintf("%s.crc", type); + d->name = basprintf("%s.crc", type); d->type |= (1 << 31); d->size = 8; sprintf(d->data, "%08x", be32_to_cpu(data_header.crc)); diff --git a/fs/efi.c b/fs/efi.c index 0f74cdafff..5ae796bdd9 100644 --- a/fs/efi.c +++ b/fs/efi.c @@ -530,8 +530,8 @@ int efi_fs_probe(struct efi_device *efidev) if (efi_loaded_image && efidev->protocol == volume) path = xstrdup("/boot"); else - path = asprintf("/efi%d", index); - device = asprintf("%s", dev_name(&efidev->dev)); + path = basprintf("/efi%d", index); + device = basprintf("%s", dev_name(&efidev->dev)); ret = make_directory(path); if (ret) diff --git a/fs/efivarfs.c b/fs/efivarfs.c index c7a282b05c..86cdcf0b59 100644 --- a/fs/efivarfs.c +++ b/fs/efivarfs.c @@ -154,7 +154,7 @@ static int efivars_create(struct device_d *dev, const char *pathname, mode_t mod name8 = xstrdup_wchar_to_char(inode->name); - inode->full_name = asprintf("%s-%pUl", name8, &inode->vendor); + inode->full_name = basprintf("%s-%pUl", name8, &inode->vendor); free(name8); efiret = RT->set_variable(inode->name, &inode->vendor, @@ -405,7 +405,7 @@ static int efivarfs_probe(struct device_d *dev) inode->vendor = vendor; name8 = xstrdup_wchar_to_char(inode->name); - inode->full_name = asprintf("%s-%pUl", name8, &vendor); + inode->full_name = basprintf("%s-%pUl", name8, &vendor); free(name8); list_add_tail(&inode->node, &priv->inodes); diff --git a/fs/fs.c b/fs/fs.c index d69e1e94cc..ad8d99b8d5 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -1298,7 +1298,8 @@ int mount(const char *device, const char *fsname, const char *_path, } if (!fsdev->linux_rootarg && fsdev->cdev && fsdev->cdev->partuuid[0] != 0) { - char *str = asprintf("root=PARTUUID=%s", fsdev->cdev->partuuid); + char *str = basprintf("root=PARTUUID=%s", + fsdev->cdev->partuuid); fsdev_set_linux_rootarg(fsdev, str); } @@ -1717,10 +1718,10 @@ const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions) if (path) return path; - newpath = asprintf("/mnt/%s", cdev->name); + newpath = basprintf("/mnt/%s", cdev->name); make_directory(newpath); - devpath = asprintf("/dev/%s", cdev->name); + devpath = basprintf("/dev/%s", cdev->name); ret = mount(devpath, NULL, newpath, fsoptions); diff --git a/fs/nfs.c b/fs/nfs.c index 87828fce13..1e874d541e 100644 --- a/fs/nfs.c +++ b/fs/nfs.c @@ -1317,19 +1317,18 @@ static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev) const char *ip; ip = ip_to_string(npriv->server); - str = asprintf("root=/dev/nfs nfsroot=%s:%s%s%s", - ip, npriv->path, rootnfsopts[0] ? "," : "", - rootnfsopts); + str = basprintf("root=/dev/nfs nfsroot=%s:%s%s%s", ip, npriv->path, + rootnfsopts[0] ? "," : "", rootnfsopts); /* forward specific mount options on demand */ if (npriv->manual_nfs_port == 1) { - tmp = asprintf("%s,port=%hu", str, npriv->nfs_port); + tmp = basprintf("%s,port=%hu", str, npriv->nfs_port); free(str); str = tmp; } if (npriv->manual_mount_port == 1) { - tmp = asprintf("%s,mountport=%hu", str, npriv->mount_port); + tmp = basprintf("%s,mountport=%hu", str, npriv->mount_port); free(str); str = tmp; } diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index f07ad5e7f9..8062baaa85 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -1269,8 +1269,8 @@ void ubifs_set_rootarg(struct ubifs_priv *priv, struct fs_device_d *fsdev) mtd = di.mtd; - str = asprintf("root=ubi0:%s ubi.mtd=%s rootfstype=ubifs", - vi.name, mtd->cdev.partname); + str = basprintf("root=ubi0:%s ubi.mtd=%s rootfstype=ubifs", + vi.name, mtd->cdev.partname); fsdev_set_linux_rootarg(fsdev, str); diff --git a/fs/uimagefs.c b/fs/uimagefs.c index c2e34a7f32..13c1fbac05 100644 --- a/fs/uimagefs.c +++ b/fs/uimagefs.c @@ -250,7 +250,7 @@ static int uimagefs_add_name(struct uimagefs_handle *priv) static int uimagefs_add_hex(struct uimagefs_handle *priv, enum uimagefs_type type, uint32_t data) { - char *val = asprintf("0x%x", data); + char *val = basprintf("0x%x", data); return uimagefs_add_str(priv, type, val); } @@ -266,7 +266,7 @@ static int __uimagefs_add_data(struct uimagefs_handle *priv, size_t offset, if (i < 0) d->name = xstrdup(name); else - d->name = asprintf("%s%d", name, i); + d->name = basprintf("%s%d", name, i); d->offset = offset; d->size = size; @@ -304,7 +304,7 @@ static int uimagefs_add_time(struct uimagefs_handle *priv) char *val; to_tm(header->ih_time, &tm); - val = asprintf("%4d-%02d-%02d %2d:%02d:%02d UTC", + val = basprintf("%4d-%02d-%02d %2d:%02d:%02d UTC", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); @@ -515,8 +515,8 @@ static int uimagefs_probe(struct device_d *dev) dev_dbg(dev, "mount: %s\n", fsdev->backingstore); if (IS_BUILTIN(CONFIG_FS_TFTP)) - priv->tmp = asprintf("/.uImage_tmp_%08x", - crc32(0, fsdev->path, strlen(fsdev->path))); + priv->tmp = basprintf("/.uImage_tmp_%08x", + crc32(0, fsdev->path, strlen(fsdev->path))); ret = __uimage_open(priv); if (ret) diff --git a/include/stdio.h b/include/stdio.h index d0817bd071..5334531849 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -15,8 +15,10 @@ int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__, int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); int vsprintf(char *buf, const char *fmt, va_list args); -char *asprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); -char *vasprintf(const char *fmt, va_list ap); +char *basprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); +int asprintf(char **strp, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); +char *bvasprintf(const char *fmt, va_list ap); +int vasprintf(char **strp, const char *fmt, va_list ap); int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); diff --git a/include/w1_mac_address.h b/include/w1_mac_address.h index 89dd914095..cd4be765f7 100644 --- a/include/w1_mac_address.h +++ b/include/w1_mac_address.h @@ -33,7 +33,7 @@ static inline int w1_local_mac_address_register(int ethid, char * oui, char *w1_ addr[i] = oui[i]; } - tmp = asprintf("%s.id", w1_dev); + tmp = basprintf("%s.id", w1_dev); if (!tmp) return -ENOMEM; diff --git a/lib/libfile.c b/lib/libfile.c index 2c72ffe066..62e9b8ed22 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -91,7 +91,7 @@ char *read_file_line(const char *fmt, ...) struct stat s; va_start(args, fmt); - filename = vasprintf(fmt, args); + filename = bvasprintf(fmt, args); va_end(args); ret = stat(filename, &s); @@ -359,8 +359,8 @@ int copy_recursive(const char *src, const char *dst) if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; - from = asprintf("%s/%s", src, d->d_name); - to = asprintf("%s/%s", dst, d->d_name); + from = basprintf("%s/%s", src, d->d_name); + to = basprintf("%s/%s", dst, d->d_name); ret = copy_recursive(from, to); if (ret) break; diff --git a/lib/logo/logo.c b/lib/logo/logo.c index 614d8c0908..9edf212232 100644 --- a/lib/logo/logo.c +++ b/lib/logo/logo.c @@ -36,7 +36,7 @@ static void load_logo(int width, void *start, void *end) char *filename; size_t size = end - start; - filename = asprintf("/logo/barebox-logo-%d.png", width); + filename = basprintf("/logo/barebox-logo-%d.png", width); write_file(filename, start, size); free(filename); } diff --git a/lib/parameter.c b/lib/parameter.c index fd05b49adf..ba6b5daead 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -341,7 +341,7 @@ static const char *param_int_get(struct device_d *dev, struct param_d *p) } free(p->value); - p->value = asprintf(pi->format, *pi->value); + p->value = basprintf(pi->format, *pi->value); return p->value; } @@ -443,7 +443,7 @@ static const char *param_enum_get(struct device_d *dev, struct param_d *p) free(p->value); if (*pe->value >= pe->num_names) - p->value = asprintf("invalid:%d", *pe->value); + p->value = basprintf("invalid:%d", *pe->value); else p->value = strdup(pe->names[*pe->value]); @@ -556,7 +556,7 @@ struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name, return ERR_PTR(ret); } - piro->param.value = asprintf(format, value); + piro->param.value = basprintf(format, value); return &piro->param; } @@ -582,7 +582,7 @@ struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name, return ERR_PTR(ret); } - piro->param.value = asprintf(format, value); + piro->param.value = basprintf(format, value); return &piro->param; } diff --git a/lib/stringlist.c b/lib/stringlist.c index 8a18366a96..8e92c1b207 100644 --- a/lib/stringlist.c +++ b/lib/stringlist.c @@ -34,7 +34,7 @@ int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...) va_start(args, fmt); - new->str = vasprintf(fmt, args); + new->str = bvasprintf(fmt, args); va_end(args); diff --git a/lib/uncompress.c b/lib/uncompress.c index 329c9fc366..3e4bc5f9e5 100644 --- a/lib/uncompress.c +++ b/lib/uncompress.c @@ -125,7 +125,8 @@ int uncompress(unsigned char *inbuf, int len, break; #endif default: - err = asprintf("cannot handle filetype %s", file_type_to_string(ft)); + err = basprintf("cannot handle filetype %s", + file_type_to_string(ft)); error_fn(err); free(err); ret = -ENOSYS; diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 00b8863957..1122a4ad38 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -646,12 +646,11 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...) } EXPORT_SYMBOL(scnprintf); -/* Simplified asprintf. */ -char *vasprintf(const char *fmt, va_list ap) +int vasprintf(char **strp, const char *fmt, va_list ap) { unsigned int len; - char *p; va_list aq; + char *p; va_copy(aq, ap); len = vsnprintf(NULL, 0, fmt, aq); @@ -659,23 +658,56 @@ char *vasprintf(const char *fmt, va_list ap) p = malloc(len + 1); if (!p) - return NULL; + return -1; vsnprintf(p, len + 1, fmt, ap); - return p; + *strp = p; + + return len; } EXPORT_SYMBOL(vasprintf); -char *asprintf(const char *fmt, ...) +char *bvasprintf(const char *fmt, va_list ap) +{ + char *p; + int len; + + len = vasprintf(&p, fmt, ap); + if (len < 0) + return NULL; + + return p; +} +EXPORT_SYMBOL(bvasprintf); + +int asprintf(char **strp, const char *fmt, ...) { va_list ap; char *p; + int len; va_start(ap, fmt); - p = vasprintf(fmt, ap); + len = vasprintf(&p, fmt, ap); va_end(ap); - return p; + return len; } EXPORT_SYMBOL(asprintf); + +char *basprintf(const char *fmt, ...) +{ + va_list ap; + char *p; + int len; + + va_start(ap, fmt); + len = vasprintf(&p, fmt, ap); + va_end(ap); + + if (len < 0) + return NULL; + + return p; +} +EXPORT_SYMBOL(basprintf); diff --git a/lib/xfuncs.c b/lib/xfuncs.c index 152081c662..aaf0788544 100644 --- a/lib/xfuncs.c +++ b/lib/xfuncs.c @@ -109,7 +109,7 @@ char *xvasprintf(const char *fmt, va_list ap) { char *p; - p = vasprintf(fmt, ap); + p = bvasprintf(fmt, ap); if (!p) panic("ERROR: out of memory\n"); return p; diff --git a/net/dhcp.c b/net/dhcp.c index 4433b442db..792ece491b 100644 --- a/net/dhcp.c +++ b/net/dhcp.c @@ -83,7 +83,7 @@ static char dhcp_tftpname[256]; static const char* dhcp_get_barebox_global(const char * var) { - char * var_global = asprintf("global.dhcp.%s", var); + char * var_global = basprintf("global.dhcp.%s", var); const char *val; if (!var_global) @@ -96,7 +96,7 @@ static const char* dhcp_get_barebox_global(const char * var) static int dhcp_set_barebox_global(const char * var, char *val) { - char * var_global = asprintf("global.dhcp.%s", var); + char * var_global = basprintf("global.dhcp.%s", var); int ret; if (!var_global) @@ -717,7 +717,7 @@ out: #ifdef CONFIG_GLOBALVAR static void dhcp_global_add(const char *var) { - char *var_global = asprintf("dhcp.%s", var); + char *var_global = basprintf("dhcp.%s", var); if (!var_global) return; diff --git a/net/dns.c b/net/dns.c index 5488e9f7b8..2acdb935ed 100644 --- a/net/dns.c +++ b/net/dns.c @@ -80,9 +80,9 @@ static int dns_send(const char *name) domain = getenv("net.domainname"); if (!strchr(name, '.') && domain && *domain) - fullname = asprintf(".%s.%s.", name, domain); + fullname = basprintf(".%s.%s.", name, domain); else - fullname = asprintf(".%s.", name); + fullname = basprintf(".%s.", name); /* replace dots in fullname with chunk len */ dotptr = fullname; diff --git a/net/ifup.c b/net/ifup.c index adab683e96..f22afc9a53 100644 --- a/net/ifup.c +++ b/net/ifup.c @@ -67,8 +67,8 @@ int ifup(const char *name, unsigned flags) for (i = 0; i < ARRAY_SIZE(vars); i++) setenv(vars[i], ""); - cmd = asprintf("source /env/network/%s", name); - cmd_discover = asprintf("/env/network/%s-discover", name); + cmd = basprintf("source /env/network/%s", name); + cmd_discover = basprintf("/env/network/%s-discover", name); ret = run_command(cmd); if (ret) { -- cgit v1.2.3 From 69858c74b2de4c03c969712fc016a8ce8ac09a0a Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 11 Apr 2016 16:12:51 +0200 Subject: move make_directory declaration to libfile.h As a utility function for file handling make_directory() is well suited for libfile. Move it there. Signed-off-by: Sascha Hauer --- commands/automount.c | 1 + commands/mkdir.c | 1 + fs/efi.c | 1 + fs/fs.c | 1 + include/fs.h | 3 --- include/libfile.h | 3 +++ lib/make_directory.c | 1 + 7 files changed, 8 insertions(+), 3 deletions(-) diff --git a/commands/automount.c b/commands/automount.c index b491d203fd..a71430c9ef 100644 --- a/commands/automount.c +++ b/commands/automount.c @@ -20,6 +20,7 @@ #include #include #include +#include static int do_automount(int argc, char *argv[]) { diff --git a/commands/mkdir.c b/commands/mkdir.c index 1f978869ab..7d024c871d 100644 --- a/commands/mkdir.c +++ b/commands/mkdir.c @@ -22,6 +22,7 @@ #include #include #include +#include static int do_mkdir(int argc, char *argv[]) { diff --git a/fs/efi.c b/fs/efi.c index 5ae796bdd9..26f2f669bb 100644 --- a/fs/efi.c +++ b/fs/efi.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include diff --git a/fs/fs.c b/fs/fs.c index ad8d99b8d5..1711a0c6aa 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -34,6 +34,7 @@ #include #include #include +#include char *mkmodestr(unsigned long mode, char *str) { diff --git a/include/fs.h b/include/fs.h index b9d1e6e09a..21490db7b9 100644 --- a/include/fs.h +++ b/include/fs.h @@ -126,9 +126,6 @@ ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset); loff_t lseek(int fildes, loff_t offset, int whence); int mkdir (const char *pathname, mode_t mode); - -/* Create a directory and its parents */ -int make_directory(const char *pathname); int rmdir (const char *pathname); const char *getcwd(void); diff --git a/include/libfile.h b/include/libfile.h index 51fa06008f..3f81718bbd 100644 --- a/include/libfile.h +++ b/include/libfile.h @@ -21,4 +21,7 @@ int compare_file(const char *f1, const char *f2); int open_and_lseek(const char *filename, int mode, loff_t pos); +/* Create a directory and its parents */ +int make_directory(const char *pathname); + #endif /* __LIBFILE_H */ diff --git a/lib/make_directory.c b/lib/make_directory.c index 7432efc192..29d08cf536 100644 --- a/lib/make_directory.c +++ b/lib/make_directory.c @@ -3,6 +3,7 @@ #include #ifdef __BAREBOX__ #include +#include #include #include #define STATIC -- cgit v1.2.3 From e1385b3399b606c2fe495f2e1967822af715edec Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 12 Apr 2016 11:20:31 +0200 Subject: move unlink_recursive declaration to libfile.h unlink_recursive is a file utility function, so move the prototype to libfile.h Signed-off-by: Sascha Hauer --- commands/loadenv.c | 1 + commands/rm.c | 1 + include/fs.h | 2 -- include/libfile.h | 2 ++ lib/unlink-recursive.c | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/commands/loadenv.c b/commands/loadenv.c index 8d6be2fa83..44e96c3b60 100644 --- a/commands/loadenv.c +++ b/commands/loadenv.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/commands/rm.c b/commands/rm.c index 5f1f582f5e..4eebb3d159 100644 --- a/commands/rm.c +++ b/commands/rm.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/include/fs.h b/include/fs.h index 21490db7b9..7081227780 100644 --- a/include/fs.h +++ b/include/fs.h @@ -179,8 +179,6 @@ void automount_remove(const char *_path); int automount_add(const char *path, const char *cmd); void automount_print(void); -int unlink_recursive(const char *path, char **failedpath); - int fsdev_open_cdev(struct fs_device_d *fsdev); const char *cdev_get_mount_path(struct cdev *cdev); const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions); diff --git a/include/libfile.h b/include/libfile.h index 3f81718bbd..de4f42dbd1 100644 --- a/include/libfile.h +++ b/include/libfile.h @@ -24,4 +24,6 @@ int open_and_lseek(const char *filename, int mode, loff_t pos); /* Create a directory and its parents */ int make_directory(const char *pathname); +int unlink_recursive(const char *path, char **failedpath); + #endif /* __LIBFILE_H */ diff --git a/lib/unlink-recursive.c b/lib/unlink-recursive.c index 78dc01593d..434fdc791b 100644 --- a/lib/unlink-recursive.c +++ b/lib/unlink-recursive.c @@ -1,4 +1,5 @@ #include +#include #include #include #include -- cgit v1.2.3 From 70bbeea7b227866bdbdef0b249ff7f8644713f15 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 7 Apr 2016 20:45:38 +0200 Subject: fs: move libc function prototypes to their correct locations This moves the function prototypes in include/fs.h which also exist in the libc to the locations they would have in libc. With this it becomes easier to share code between barebox and userspace since the usual libc include files will exist. Also users of the libc functions no longer have to include the barebox internal fs.h header. Signed-off-by: Sascha Hauer --- include/dirent.h | 20 +++++++++++ include/fcntl.h | 100 +++------------------------------------------------- include/fs.h | 51 ++++----------------------- include/sys/ioctl.h | 6 ++++ include/sys/mount.h | 8 +++++ include/sys/stat.h | 9 +++++ include/unistd.h | 24 +++++++++++++ 7 files changed, 78 insertions(+), 140 deletions(-) create mode 100644 include/dirent.h create mode 100644 include/sys/ioctl.h create mode 100644 include/sys/mount.h create mode 100644 include/sys/stat.h create mode 100644 include/unistd.h diff --git a/include/dirent.h b/include/dirent.h new file mode 100644 index 0000000000..5ee4c2063e --- /dev/null +++ b/include/dirent.h @@ -0,0 +1,20 @@ +#ifndef __DIRENT_H +#define __DIRENT_H + +struct dirent { + char d_name[256]; +}; + +typedef struct dir { + struct device_d *dev; + struct fs_driver_d *fsdrv; + struct node_d *node; + struct dirent d; + void *priv; /* private data for the fs driver */ +} DIR; + +DIR *opendir(const char *pathname); +struct dirent *readdir(DIR *dir); +int closedir(DIR *dir); + +#endif /* __DIRENT_H */ diff --git a/include/fcntl.h b/include/fcntl.h index 12f370a418..98020bdfb1 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -1,5 +1,5 @@ -#ifndef _ASM_GENERIC_FCNTL_H -#define _ASM_GENERIC_FCNTL_H +#ifndef __FCNTL_H +#define __FCNTL_H #include @@ -24,97 +24,7 @@ #define O_RWSIZE_4 004000000 #define O_RWSIZE_8 010000000 -#define F_DUPFD 0 /* dup */ -#define F_GETFD 1 /* get close_on_exec */ -#define F_SETFD 2 /* set/clear close_on_exec */ -#define F_GETFL 3 /* get file->f_flags */ -#define F_SETFL 4 /* set file->f_flags */ -#ifndef F_GETLK -#define F_GETLK 5 -#define F_SETLK 6 -#define F_SETLKW 7 -#endif -#ifndef F_SETOWN -#define F_SETOWN 8 /* for sockets. */ -#define F_GETOWN 9 /* for sockets. */ -#endif -#ifndef F_SETSIG -#define F_SETSIG 10 /* for sockets. */ -#define F_GETSIG 11 /* for sockets. */ -#endif +int open(const char *pathname, int flags, ...); +int creat(const char *pathname, mode_t mode); -/* for F_[GET|SET]FL */ -#define FD_CLOEXEC 1 /* actually anything with low bit set goes */ - -/* for posix fcntl() and lockf() */ -#ifndef F_RDLCK -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 -#endif - -/* for old implementation of bsd flock () */ -#ifndef F_EXLCK -#define F_EXLCK 4 /* or 3 */ -#define F_SHLCK 8 /* or 4 */ -#endif - -/* for leases */ -#ifndef F_INPROGRESS -#define F_INPROGRESS 16 -#endif - -/* operations for bsd flock(), also used by the kernel implementation */ -#define LOCK_SH 1 /* shared lock */ -#define LOCK_EX 2 /* exclusive lock */ -#define LOCK_NB 4 /* or'd with one of the above to prevent - blocking */ -#define LOCK_UN 8 /* remove lock */ - -#define LOCK_MAND 32 /* This is a mandatory flock ... */ -#define LOCK_READ 64 /* which allows concurrent read operations */ -#define LOCK_WRITE 128 /* which allows concurrent write operations */ -#define LOCK_RW 192 /* which allows concurrent read & write ops */ - -#define F_LINUX_SPECIFIC_BASE 1024 - -#ifndef HAVE_ARCH_STRUCT_FLOCK -#ifndef __ARCH_FLOCK_PAD -#define __ARCH_FLOCK_PAD -#endif - -struct flock { - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - pid_t l_pid; - __ARCH_FLOCK_PAD -}; -#endif - -#ifndef CONFIG_64BIT - -#ifndef F_GETLK64 -#define F_GETLK64 12 /* using 'struct flock64' */ -#define F_SETLK64 13 -#define F_SETLKW64 14 -#endif - -#ifndef HAVE_ARCH_STRUCT_FLOCK64 -#ifndef __ARCH_FLOCK64_PAD -#define __ARCH_FLOCK64_PAD -#endif - -struct flock64 { - short l_type; - short l_whence; - loff_t l_start; - loff_t l_len; - pid_t l_pid; - __ARCH_FLOCK64_PAD -}; -#endif -#endif /* !CONFIG_64BIT */ - -#endif /* _ASM_GENERIC_FCNTL_H */ +#endif /* __FCNTL_H */ diff --git a/include/fs.h b/include/fs.h index 7081227780..135cb57be4 100644 --- a/include/fs.h +++ b/include/fs.h @@ -1,6 +1,12 @@ #ifndef __FS_H #define __FS_H +#include +#include +#include +#include +#include +#include #include #include #include @@ -11,18 +17,6 @@ struct partition; struct node_d; struct stat; -struct dirent { - char d_name[256]; -}; - -typedef struct dir { - struct device_d *dev; - struct fs_driver_d *fsdrv; - struct node_d *node; - struct dirent d; - void *priv; /* private data for the fs driver */ -} DIR; - typedef struct filep { struct fs_device_d *fsdev; /* The device this FILE belongs to */ char *path; @@ -107,40 +101,7 @@ struct fs_device_d { #define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv) -/* - * standard posix file functions - */ -int open(const char *pathname, int flags, ...); -int creat(const char *pathname, mode_t mode); -int unlink(const char *pathname); -int close(int fd); int flush(int fd); -int lstat(const char *filename, struct stat *s); -int stat(const char *filename, struct stat *s); -int fstat(int fd, struct stat *s); -ssize_t read(int fd, void *buf, size_t count); -ssize_t pread(int fd, void *buf, size_t count, loff_t offset); -int ioctl(int fd, int request, void *buf); -ssize_t write(int fd, const void *buf, size_t count); -ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset); - -loff_t lseek(int fildes, loff_t offset, int whence); -int mkdir (const char *pathname, mode_t mode); -int rmdir (const char *pathname); - -const char *getcwd(void); -int chdir(const char *pathname); - -DIR *opendir(const char *pathname); -struct dirent *readdir(DIR *dir); -int closedir(DIR *dir); - -int symlink(const char *pathname, const char *newpath); -int readlink(const char *path, char *buf, size_t bufsiz); - -int mount (const char *device, const char *fsname, const char *path, - const char *fsoptions); -int umount(const char *pathname); int umount_by_cdev(struct cdev *cdev); /* not-so-standard functions */ diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h new file mode 100644 index 0000000000..6d6d3f5c00 --- /dev/null +++ b/include/sys/ioctl.h @@ -0,0 +1,6 @@ +#ifndef __SYS_IOCTL_H +#define __SYS_IOCTL_H + +int ioctl(int fd, int request, void *buf); + +#endif /* __SYS_IOCTL_H */ diff --git a/include/sys/mount.h b/include/sys/mount.h new file mode 100644 index 0000000000..978f3406e8 --- /dev/null +++ b/include/sys/mount.h @@ -0,0 +1,8 @@ +#ifndef __SYS_MOUNT_H +#define __SYS_MOUNT_H + +int mount(const char *device, const char *fsname, const char *path, + const char *fsoptions); +int umount(const char *pathname); + +#endif /* __SYS_MOUNT_H */ diff --git a/include/sys/stat.h b/include/sys/stat.h new file mode 100644 index 0000000000..037e5f136d --- /dev/null +++ b/include/sys/stat.h @@ -0,0 +1,9 @@ +#ifndef __STAT_H +#define __STAT_H + +#include +#include + +int mkdir (const char *pathname, mode_t mode); + +#endif /* __STAT_H */ diff --git a/include/unistd.h b/include/unistd.h new file mode 100644 index 0000000000..31f430a5b6 --- /dev/null +++ b/include/unistd.h @@ -0,0 +1,24 @@ +#ifndef __UNISTD_H +#define __UNISTD_H + +#include + +struct stat; + +int unlink(const char *pathname); +int close(int fd); +int lstat(const char *filename, struct stat *s); +int stat(const char *filename, struct stat *s); +int fstat(int fd, struct stat *s); +ssize_t read(int fd, void *buf, size_t count); +ssize_t pread(int fd, void *buf, size_t count, loff_t offset); +ssize_t write(int fd, const void *buf, size_t count); +ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset); +loff_t lseek(int fildes, loff_t offset, int whence); +int rmdir (const char *pathname); +int symlink(const char *pathname, const char *newpath); +int readlink(const char *path, char *buf, size_t bufsiz); +int chdir(const char *pathname); +const char *getcwd(void); + +#endif /* __UNISTD_H */ -- cgit v1.2.3 From 01f8f60cf06e180b2b5eb96ceb162473c0cb196a Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 14 Apr 2016 08:48:59 +0200 Subject: stdio: rename getc to getchar The function we have implemented as getc has the semantics of the standard function getchar, so rename it accorgingly. Signed-off-by: Sascha Hauer --- arch/arm/mach-at91/bootstrap.c | 16 ++++++++-------- commands/edit.c | 2 +- commands/loads.c | 6 +++--- commands/mmc_extcsd.c | 4 ++-- common/console.c | 10 +++++----- common/console_countdown.c | 2 +- common/console_simple.c | 6 +++--- common/password.c | 2 +- drivers/mtd/nand/nand_imx_bbm.c | 2 +- include/stdio.h | 4 ++-- lib/readkey.c | 8 ++++---- lib/readline_simple.c | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/arch/arm/mach-at91/bootstrap.c b/arch/arm/mach-at91/bootstrap.c index 47e78965d9..8502bb00ff 100644 --- a/arch/arm/mach-at91/bootstrap.c +++ b/arch/arm/mach-at91/bootstrap.c @@ -99,49 +99,49 @@ static void boot_nand_barebox_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_nand(true); - getc(); + getchar(); } static void boot_nand_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_nand(false); - getc(); + getchar(); } static void boot_m25p80_barebox_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_nand(true); - getc(); + getchar(); } static void boot_m25p80_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_nand(false); - getc(); + getchar(); } static void boot_dataflash_barebox_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_dataflash(true); - getc(); + getchar(); } static void boot_dataflash_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_dataflash(false); - getc(); + getchar(); } static void boot_mmc_disk_action(struct menu *m, struct menu_entry *me) { at91bootstrap_boot_mmc(); - getc(); + getchar(); } static void boot_reset_action(struct menu *m, struct menu_entry *me) @@ -234,7 +234,7 @@ static int at91_bootstrap(void) { if (is_menu()) { printf("press 'm' to start the menu\n"); - if (tstc() && getc() == 'm') + if (tstc() && getchar() == 'm') at91_bootstrap_menu(); } diff --git a/commands/edit.c b/commands/edit.c index c014892fc4..a5415a6e5b 100644 --- a/commands/edit.c +++ b/commands/edit.c @@ -367,7 +367,7 @@ static void getwinsize(void) printf(ESC "7" ESC "[r" ESC "[999;999H" ESC "[6n"); - while ((r = getc()) != 'R') { + while ((r = getchar()) != 'R') { buf[i] = r; i++; } diff --git a/commands/loads.c b/commands/loads.c index aa3095ee8c..eb3e109b0b 100644 --- a/commands/loads.c +++ b/commands/loads.c @@ -59,7 +59,7 @@ static int do_load_serial(int argc, char *argv[]) */ for (i=0; i<100; ++i) { if (tstc()) { - (void) getc(); + (void) getchar(); } udelay(1000); } @@ -142,7 +142,7 @@ static int read_record(char *buf, ulong len) --len; /* always leave room for terminating '\0' byte */ for (p=buf; p < buf+len; ++p) { - c = getc(); /* read character */ + c = getchar(); /* read character */ if (do_echo) putchar(c); @@ -180,7 +180,7 @@ static int do_save_serial(int argc, char *argv[]) printf ("## Ready for S-Record upload, press ENTER to proceed ...\n"); for (;;) { - if (getc() == '\r') + if (getchar() == '\r') break; } if (save_serial(offset, size)) { diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c index d05128c6e7..fa4e29c3da 100644 --- a/commands/mmc_extcsd.c +++ b/commands/mmc_extcsd.c @@ -1867,14 +1867,14 @@ static int request_write_operation(void) int c; printf("This is a one time programmable field!\nDo you want to write? [y/N] "); - c = getc(); + c = getchar(); /* default is N */ if (c == 0xD) { printf("\n"); return 0; } printf("%c", c); - getc(); /* wait for carriage return */ + getchar(); /* wait for carriage return */ printf("\n"); if (c == 'y' || c == 'Y') return 1; diff --git a/common/console.c b/common/console.c index f0988b8bc0..37574b9b01 100644 --- a/common/console.c +++ b/common/console.c @@ -164,7 +164,7 @@ int console_set_baudrate(struct console_device *cdev, unsigned baudrate) if (cdev->f_active) { mdelay(50); do { - c = getc(); + c = getchar(); } while (c != '\r' && c != '\n'); } @@ -345,7 +345,7 @@ static int tstc_raw(void) return 0; } -int getc(void) +int getchar(void) { unsigned char ch; uint64_t start; @@ -380,14 +380,14 @@ int getc(void) return ch; } -EXPORT_SYMBOL(getc); +EXPORT_SYMBOL(getchar); int fgetc(int fd) { char c; if (!fd) - return getc(); + return getchar(); return read(fd, &c, 1); } EXPORT_SYMBOL(fgetc); @@ -476,7 +476,7 @@ int ctrlc (void) { poller_call(); - if (tstc() && getc() == 3) + if (tstc() && getchar() == 3) return 1; return 0; } diff --git a/common/console_countdown.c b/common/console_countdown.c index ffbdb4fa2d..c0c8c95022 100644 --- a/common/console_countdown.c +++ b/common/console_countdown.c @@ -39,7 +39,7 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key) do { if (tstc()) { - key = getc(); + key = getchar(); if (flags & CONSOLE_COUNTDOWN_ANYKEY) goto out; if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n') diff --git a/common/console_simple.c b/common/console_simple.c index 69e76593ad..9675cbb0a6 100644 --- a/common/console_simple.c +++ b/common/console_simple.c @@ -48,13 +48,13 @@ int tstc(void) } EXPORT_SYMBOL(tstc); -int getc(void) +int getchar(void) { if (!console) return -EINVAL; return console->getc(console); } -EXPORT_SYMBOL(getc); +EXPORT_SYMBOL(getchar); void console_flush(void) { @@ -67,7 +67,7 @@ EXPORT_SYMBOL(console_flush); /* test if ctrl-c was pressed */ int ctrlc (void) { - if (tstc() && getc() == 3) + if (tstc() && getchar() == 3) return 1; return 0; } diff --git a/common/password.c b/common/password.c index 05e61801f0..d52b746f0f 100644 --- a/common/password.c +++ b/common/password.c @@ -63,7 +63,7 @@ int password(unsigned char *passwd, size_t length, int flags, int timeout) do { if (tstc()) { - ch = getc(); + ch = getchar(); switch (ch) { case '\r': diff --git a/drivers/mtd/nand/nand_imx_bbm.c b/drivers/mtd/nand/nand_imx_bbm.c index 5caa0a26c3..251dfe5d3f 100644 --- a/drivers/mtd/nand/nand_imx_bbm.c +++ b/drivers/mtd/nand/nand_imx_bbm.c @@ -188,7 +188,7 @@ static int do_imx_nand_bbm(int argc, char *argv[]) int c; printf("create flash bbt (y/n)?"); - c = getc(); + c = getchar(); if (c == 'y') yes = 1; printf("\n"); diff --git a/include/stdio.h b/include/stdio.h index 5334531849..1ead0e6e00 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -28,7 +28,7 @@ int tstc(void); /* stdout */ void console_putc(unsigned int ch, const char c); -int getc(void); +int getchar(void); int console_puts(unsigned int ch, const char *s); void console_flush(void); @@ -44,7 +44,7 @@ static inline int console_puts(unsigned int ch, const char *str) return 0; } -static inline int getc(void) +static inline int getchar(void) { return -EINVAL; } diff --git a/lib/readkey.c b/lib/readkey.c index 2073a732f4..2870a5a9fe 100644 --- a/lib/readkey.c +++ b/lib/readkey.c @@ -53,15 +53,15 @@ int read_key(void) { char c; char esc[5]; - c = getc(); + c = getchar(); if (c == 27) { int i = 0; - esc[i++] = getc(); - esc[i++] = getc(); + esc[i++] = getchar(); + esc[i++] = getchar(); if (isdigit(esc[1])) { while(1) { - esc[i] = getc(); + esc[i] = getchar(); if (esc[i++] == '~') break; if (i == ARRAY_SIZE(esc)) diff --git a/lib/readline_simple.c b/lib/readline_simple.c index 1a40d113e3..c2960665fb 100644 --- a/lib/readline_simple.c +++ b/lib/readline_simple.c @@ -70,7 +70,7 @@ int readline (const char *prompt, char *line, int len) show_activity(0); } #endif - c = getc(); + c = getchar(); /* * Special character handling -- cgit v1.2.3 From 473d6f8a7a16d1440f360b8562b746fbadee2d82 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 14 Apr 2016 09:35:13 +0200 Subject: stdio: replace fprintf(stderr,...) with eprintf We have a shortcut for fprintf(stderr, so use it. This is done to be able to remove fprintf in the next step. Signed-off-by: Sascha Hauer --- commands/clk.c | 2 +- commands/loadb.c | 7 +++---- commands/menu.c | 4 ++-- commands/miitool.c | 2 +- common/imd.c | 4 ++-- include/mtd/utils.h | 2 +- scripts/bareboximd.c | 2 ++ 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/commands/clk.c b/commands/clk.c index 65832d4985..f862c45b2a 100644 --- a/commands/clk.c +++ b/commands/clk.c @@ -97,7 +97,7 @@ static int do_clk_get_rate(int argc, char *argv[]) } if (optind == argc) { - fprintf(stderr, "No clock name given\n"); + eprintf("No clock name given\n"); return COMMAND_ERROR_USAGE; } diff --git a/commands/loadb.c b/commands/loadb.c index 6223512477..6180ce371a 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -183,8 +183,7 @@ static int os_data_save(void) ret = write(ofd, write_buffer, MAX_WRITE_BUFFER); if (ret < 0) { - fprintf(stderr, - "write to device failed\n"); + eprintf("write to device failed\n"); return ret; } write_idx = 0; @@ -563,7 +562,7 @@ static ulong load_serial_bin(void) /* Try to allocate the buffer we shall write to files */ write_buffer = malloc(MAX_WRITE_BUFFER); if (write_buffer == NULL) { - fprintf(stderr, "could not allocate file i/o buffer\n"); + eprintf("could not allocate file i/o buffer\n"); return -ENOMEM; } @@ -585,7 +584,7 @@ static ulong load_serial_bin(void) if (write_idx > 0) { i = write(ofd, write_buffer, write_idx); if (i < 0) { - fprintf(stderr, "write to device failed\n"); + eprintf("write to device failed\n"); size = i; goto err_quit; } diff --git a/commands/menu.c b/commands/menu.c index 2008aa5e9d..9ec2d579b7 100644 --- a/commands/menu.c +++ b/commands/menu.c @@ -160,8 +160,8 @@ static int do_menu_add(struct cmd_menu *cm) free: eprintf("Menu '%s' add fail", cm->menu); if (ret == -EEXIST) - eputs(" already exist"); - eputs("\n"); + eprintf(" already exist"); + eprintf("\n"); menu_free(m); diff --git a/commands/miitool.c b/commands/miitool.c index ba6e604633..07bce18651 100644 --- a/commands/miitool.c +++ b/commands/miitool.c @@ -120,7 +120,7 @@ static int show_basic_mii(struct mii_bus *mii, struct phy_device *phydev, if (mii_val[MII_BMCR] == 0xffff || mii_val[MII_BMSR] == 0x0000) { - fprintf(stderr, " No MII transceiver present!.\n"); + eprintf(" No MII transceiver present!.\n"); return -1; } diff --git a/common/imd.c b/common/imd.c index 241ebbdaed..159b73a828 100644 --- a/common/imd.c +++ b/common/imd.c @@ -306,7 +306,7 @@ int imd_command(int argc, char *argv[]) case 't': type = imd_name_to_type(optarg); if (type == IMD_TYPE_INVALID) { - fprintf(stderr, "no such type: %s\n", optarg); + eprintf("no such type: %s\n", optarg); return -ENOSYS; } break; @@ -325,7 +325,7 @@ int imd_command(int argc, char *argv[]) } if (optind == argc) { - fprintf(stderr, "No image given\n"); + eprintf("No image given\n"); return -ENOSYS; } diff --git a/include/mtd/utils.h b/include/mtd/utils.h index fca64abd9d..58f89df90c 100644 --- a/include/mtd/utils.h +++ b/include/mtd/utils.h @@ -41,7 +41,7 @@ #define sys_errmsg errmsg #define warnmsg(fmt, ...) do { \ - fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \ + eprintf("%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \ } while(0) #endif /* INCLUDE_MTD_UTILS_H */ diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c index d4da681eca..7d4cbeb9a8 100644 --- a/scripts/bareboximd.c +++ b/scripts/bareboximd.c @@ -37,6 +37,8 @@ #include "../include/image-metadata.h" +#define eprintf(args...) fprintf(stderr, ## args) + static void debug(const char *fmt, ...) { va_list ap; -- cgit v1.2.3 From 5559bfd2719f0b0795a6ce66b859d879271bb1e4 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 14 Apr 2016 09:37:28 +0200 Subject: stdio: Replace FILE functions with filedescriptor functions We have defined stdin, stdout and stderr as integer file descriptors, but normally they should be FILE *. Also fprintf, fputc and fputs take file descriptors instead of FILE *. As FILE * are inconvenient in the barebox environment replace the f* functions with the corresponding d* functions. dprintf is POSIX conform whereas dputc and dputs are barebox specific, but do not conflict with any stdc function. fgetc is unused and can be removed without replacing it. Signed-off-by: Sascha Hauer --- commands/echo.c | 10 +++++----- common/console.c | 10 ---------- common/console_common.c | 18 +++++++++--------- common/globalvar.c | 2 +- include/stdio.h | 21 +++++++++------------ 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/commands/echo.c b/commands/echo.c index 7d47ab7ca7..8853ee0a30 100644 --- a/commands/echo.c +++ b/commands/echo.c @@ -27,7 +27,7 @@ static int do_echo(int argc, char *argv[]) { int i, optind = 1; - int fd = stdout, opt, newline = 1; + int fd = STDOUT_FILENO, opt, newline = 1; char *file = NULL; int oflags = O_WRONLY | O_CREAT; char str[CONFIG_CBSIZE]; @@ -81,17 +81,17 @@ exit_parse: for (i = optind; i < argc; i++) { if (i > optind) - fputc(fd, ' '); + dputc(fd, ' '); if (process_escape) { process_escape_sequence(argv[i], str, CONFIG_CBSIZE); - fputs(fd, str); + dputs(fd, str); } else { - fputs(fd, argv[i]); + dputs(fd, argv[i]); } } if (newline) - fputc(fd, '\n'); + dputc(fd, '\n'); if (file) close(fd); diff --git a/common/console.c b/common/console.c index 37574b9b01..a67f169b42 100644 --- a/common/console.c +++ b/common/console.c @@ -382,16 +382,6 @@ int getchar(void) } EXPORT_SYMBOL(getchar); -int fgetc(int fd) -{ - char c; - - if (!fd) - return getchar(); - return read(fd, &c, 1); -} -EXPORT_SYMBOL(fgetc); - int tstc(void) { return kfifo_len(console_input_fifo) || tstc_raw(); diff --git a/common/console_common.c b/common/console_common.c index a9bbce9a28..2e5869fab0 100644 --- a/common/console_common.c +++ b/common/console_common.c @@ -278,7 +278,7 @@ EXPORT_SYMBOL(console_get_first_active); #endif /* !CONFIG_CONSOLE_NONE */ -int fprintf(int file, const char *fmt, ...) +int dprintf(int file, const char *fmt, ...) { va_list args; char printbuffer[CFG_PBSIZE]; @@ -293,30 +293,30 @@ int fprintf(int file, const char *fmt, ...) va_end(args); /* Print the string */ - return fputs(file, printbuffer); + return dputs(file, printbuffer); } -EXPORT_SYMBOL(fprintf); +EXPORT_SYMBOL(dprintf); -int fputs(int fd, const char *s) +int dputs(int fd, const char *s) { if (fd == 1) return puts(s); else if (fd == 2) - return eputs(s); + return console_puts(CONSOLE_STDERR, s); else return write(fd, s, strlen(s)); } -EXPORT_SYMBOL(fputs); +EXPORT_SYMBOL(dputs); -int fputc(int fd, char c) +int dputc(int fd, char c) { if (fd == 1) putchar(c); else if (fd == 2) - eputc(c); + console_putc(CONSOLE_STDERR, c); else return write(fd, &c, 1); return 0; } -EXPORT_SYMBOL(fputc); +EXPORT_SYMBOL(dputc); diff --git a/common/globalvar.c b/common/globalvar.c index d5dd461963..bc1734d58d 100644 --- a/common/globalvar.c +++ b/common/globalvar.c @@ -51,7 +51,7 @@ static int nv_save(const char *name, const char *val) if (fd < 0) return fd; - fprintf(fd, "%s", val); + dprintf(fd, "%s", val); close(fd); diff --git a/include/stdio.h b/include/stdio.h index 1ead0e6e00..5e615718c1 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -89,23 +89,20 @@ static inline void putchar(char c) console_putc(CONSOLE_STDOUT, c); } -/* stderr */ -#define eputc(c) console_putc(CONSOLE_STDERR, c) -#define eputs(s) console_puts(CONSOLE_STDERR, s) -#define eprintf(fmt,args...) fprintf(stderr,fmt ,##args) - /* * FILE based functions */ -#define stdin 0 -#define stdout 1 -#define stderr 2 +/* stderr */ +#define eprintf(fmt,args...) dprintf(STDERR_FILENO, fmt ,##args) + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 #define MAX_FILES 128 -int fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); -int fputs(int file, const char *s); -int fputc(int file, const char c); -int fgetc(int file); +int dprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); +int dputs(int file, const char *s); +int dputc(int file, const char c); #endif /* __STDIO_H */ -- cgit v1.2.3 From 158279def1295e553683a1523a61858acffb18b4 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 14 Apr 2016 09:45:28 +0200 Subject: stdio: Whitespace cleanup Replace the tabs with spaces before the function names. Signed-off-by: Sascha Hauer --- include/stdio.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index 5e615718c1..7b2a42b817 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -9,30 +9,30 @@ */ /* serial stuff */ -void serial_printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); +void serial_printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); -int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); -int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); -int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); -int vsprintf(char *buf, const char *fmt, va_list args); +int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); +int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); +int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); +int vsprintf(char *buf, const char *fmt, va_list args); char *basprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); int asprintf(char **strp, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); char *bvasprintf(const char *fmt, va_list ap); int vasprintf(char **strp, const char *fmt, va_list ap); -int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); -int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); +int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); +int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); #ifndef CONFIG_CONSOLE_NONE /* stdin */ -int tstc(void); +int tstc(void); /* stdout */ -void console_putc(unsigned int ch, const char c); -int getchar(void); -int console_puts(unsigned int ch, const char *s); -void console_flush(void); +void console_putc(unsigned int ch, const char c); +int getchar(void); +int console_puts(unsigned int ch, const char *s); +void console_flush(void); -int vprintf(const char *fmt, va_list args); +int vprintf(const char *fmt, va_list args); #else static inline int tstc(void) { -- cgit v1.2.3 From 18f0d2221a4c781dad2a224f8ac17e7c95fd1d9c Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 27 Apr 2016 07:38:41 -0700 Subject: commands: mmc_extcsd: Fix incorrect usage of sprintf In a number of places print_field_ge_v7() and print_field() function would call sprintf() without providing is with appropriate output buffer (str is initialized to NULL). Replace the sprintf() with basprintf() to fix that. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/mmc_extcsd.c | 79 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c index fa4e29c3da..d7fc50697c 100644 --- a/commands/mmc_extcsd.c +++ b/commands/mmc_extcsd.c @@ -153,15 +153,16 @@ static int print_field_ge_v7(u8 *reg, int index) tmp = get_field_val(DATA_SECTOR_SIZE, 0, 0x1); if (tmp64 == 0xFFFFFFFF) if (tmp) - str = "16 TB"; + str = strdup("16 TB"); else - str = "2 TB"; + str = strdup("2 TB"); else if (tmp) - sprintf(str, "%llu B", tmp64 * 4096); + str = basprintf("%llu B", tmp64 * 4096); else - sprintf(str, "%llu B", tmp64 * 512); + str = basprintf("%llu B", tmp64 * 512); printf("\tMax_Pre_Loading_Data_Size: %s\n", str); + free(str); return 1; /* EXT_CSD_PRE_LOADING_DATA_SIZE */ @@ -181,15 +182,16 @@ static int print_field_ge_v7(u8 *reg, int index) tmp = get_field_val(DATA_SECTOR_SIZE, 0, 0x1); if (tmp64 == 0xFFFFFFFF) if (tmp) - str = "16 TB"; + str = strdup("16 TB"); else - str = "2 TB"; + str = strdup("2 TB"); else if (tmp) - sprintf(str, "%llu B", tmp64 * 4096); + str = basprintf("%llu B", tmp64 * 4096); else - sprintf(str, "%llu B", tmp64 * 512); + str = basprintf("%llu B", tmp64 * 512); printf("\tPre_Loading_Data_Size: %s\n", str); + free(str); return 1; case EXT_CSD_FFU_STATUS: @@ -319,12 +321,13 @@ static int print_field_ge_v7(u8 *reg, int index) val = get_field_val(DEVICE_LIFE_TIME_EST_TYP_A, 0, 0xFF); val = val * 10; if (val == 0) - str = "not defined"; + str = strdup("not defined"); else if (val == 0xB) - str = "maximum"; + str = strdup("maximum"); else - sprintf(str, "%u%% - %u%%", (val - 10), val); + str = basprintf("%u%% - %u%%", (val - 10), val); printf("\tDevice life time, type A (estimation): %s\n", str); + free(str); return 1; case EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B: @@ -332,12 +335,13 @@ static int print_field_ge_v7(u8 *reg, int index) val = get_field_val(DEVICE_LIFE_TIME_EST_TYP_B, 0, 0xFF); val = val * 10; if (val == 0) - str = "not defined"; + str = strdup("not defined"); else if (val == 0xB) - str = "maximum"; + str = strdup("maximum"); else - sprintf(str, "%u%% - %u%%", (val - 10), val); + str = basprintf("%u%% - %u%%", (val - 10), val); printf("\tDevice life time, type B (estimation): %s\n", str); + free(str); return 1; /* EXT_CSD_NMBR_OF_FW_SCTRS_CRRCTLY_PRGRMD */ @@ -1687,11 +1691,12 @@ static int print_field(u8 *reg, int index) val = get_field_val(SLEEP_NOTIFICATION_TIME, 0, 0xFF); val = 100 << val; if (val) - sprintf(str, "Sleep Notification timeout values: %u us", - val); + str = basprintf("Sleep Notification timeout values: %u us", + val); else - str = "Not defined"; + str = strdup("Not defined"); printf("\t[7-0] %s\n", str); + free(str); return 1; case EXT_CSD_S_A_TIMEOUT: @@ -1699,10 +1704,11 @@ static int print_field(u8 *reg, int index) val = get_field_val(S_A_TIMEOUT, 0, 0xFF); val = 100 << val; if (val) - sprintf(str, "Sleep/awake timeout values: %u ns", val); + str = basprintf("Sleep/awake timeout values: %u ns", val); else - str = "Not defined"; + str = strdup("Not defined"); printf("\t[7-0] %s\n", str); + free(str); return 1; case EXT_CSD_PRODUCTION_ST8_AWARENSS_TIMEOUT: @@ -1710,12 +1716,13 @@ static int print_field(u8 *reg, int index) val = get_field_val(PRODUCTION_ST8_AWARENSS_TIMEOUT, 0, 0xFF); val = 100 << val; if (val) - sprintf(str, + str = basprintf( "Production State Awareness timeout definition: %u us", val); else - str = "Not defined"; + str = strdup("Not defined"); printf("\t[7-0] %s\n", str); + free(str); return 1; case EXT_CSD_S_C_VCCQ: @@ -1723,10 +1730,11 @@ static int print_field(u8 *reg, int index) val = get_field_val(S_C_VCCQ, 0, 0xF); val = 1 << val; if (val) - sprintf(str, "S_C_VCCQ Sleep Current: %u uA", val); + str = basprintf("S_C_VCCQ Sleep Current: %u uA", val); else - str = "Not defined"; + str = strdup("Not defined"); printf("\t[3-0] %s\n", str); + free(str); return 1; case EXT_CSD_S_C_VCC: @@ -1734,20 +1742,22 @@ static int print_field(u8 *reg, int index) val = get_field_val(S_C_VCC, 0, 0xFF); val = 1 << val; if (val) - sprintf(str, "S_C_VCC Sleep Current: %u uA", val); + str = basprintf("S_C_VCC Sleep Current: %u uA", val); else - str = "Not defined"; + str = strdup("Not defined"); printf("\t[3-0] %s\n", str); + free(str); return 1; case EXT_CSD_HC_WP_GRP_SIZE: print_field_caption(HC_WP_GRP_SIZE, R); val = get_field_val(HC_WP_GRP_SIZE, 0, 0xFF); if (val) - sprintf(str, "Write protect group size: %u", val); + str = basprintf("Write protect group size: %u", val); else - str = "No support"; + str = strdup("No support"); printf("\t[7-0] %s\n", str); + free(str); return 1; case EXT_CSD_REL_WR_SEC_C: @@ -1761,10 +1771,11 @@ static int print_field(u8 *reg, int index) val = get_field_val(ERASE_TIMEOUT_MULT, 0, 0xFF); val = val * 300; if (val) - sprintf(str, "Erase timeout values: %u", val); + str = basprintf("Erase timeout values: %u", val); else - str = "No support"; + str = strdup("No support"); printf("\t[7-0] %s\n", str); + free(str); return 1; case EXT_CSD_HC_ERASE_GRP_SIZE: @@ -1772,10 +1783,11 @@ static int print_field(u8 *reg, int index) val = get_field_val(HC_ERASE_GRP_SIZE, 0, 0xFF); val = val * 524288; if (val) - sprintf(str, "Erase-unit size: %u", val); + str = basprintf("Erase-unit size: %u", val); else - str = "No support"; + str = strdup("No support"); printf("\t[7-0] %s\n", str); + free(str); return 1; case EXT_CSD_ACC_SIZE: @@ -1783,10 +1795,11 @@ static int print_field(u8 *reg, int index) val = get_field_val(ACC_SIZE, 0, 0xF); val = val * 512; if (val) - sprintf(str, "Superpage size: %u", val); + str = basprintf("Superpage size: %u", val); else - str = "Not defined"; + str = strdup("Not defined"); printf("\t[3-0] %s\n", str); + free(str); return 1; case EXT_CSD_BOOT_SIZE_MULT: -- cgit v1.2.3