From 7cceef54a045ca8b9b33145b708d843b371718ba Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 2 Jun 2022 21:59:15 +0200 Subject: commands: ls: explicitly check for directories with S_ISDIR S_ISDIR(mode) is implemented as (mode & S_IFMT) == S_IFDIR, which accounts for file modes setting multiple bits. So far, this was not the case, but upcoming S_IFBLK equals (S_IFCHR | S_IFDIR), which would fail the existing checks, so prepare for that by fixing them. No functional change. There are no other instances of this elsewhere in the code base. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220602195916.9061-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- commands/ls.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'commands') diff --git a/commands/ls.c b/commands/ls.c index bedf2e1c42..1192aed971 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -63,10 +63,10 @@ int ls(const char *path, ulong flags) if (stat(path, &s)) return -errno; - if (flags & LS_SHOWARG && s.st_mode & S_IFDIR) + if (flags & LS_SHOWARG && S_ISDIR(s.st_mode)) printf("%s:\n", path); - if (!(s.st_mode & S_IFDIR)) { + if (!S_ISDIR(s.st_mode)) { ls_one(path, path); return 0; } @@ -112,7 +112,7 @@ int ls(const char *path, ulong flags) continue; } - if (s.st_mode & S_IFDIR) + if (S_ISDIR(s.st_mode)) ls(tmp, flags); } @@ -171,7 +171,7 @@ static int do_ls(int argc, char *argv[]) continue; } - if (!(s.st_mode & S_IFDIR)) { + if (!S_ISDIR(s.st_mode)) { if (flags & LS_COLUMN) string_list_add_sorted(&sl, argv[o]); else @@ -197,7 +197,7 @@ static int do_ls(int argc, char *argv[]) continue; } - if (s.st_mode & S_IFDIR) { + if (S_ISDIR(s.st_mode)) { ret = ls(argv[o], flags); if (ret) { perror("ls"); -- cgit v1.2.1 From 84173bf3d0ccc4036a16c4b074642aea59648063 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 2 Jun 2022 21:59:16 +0200 Subject: block: set S_IFBLK for block devices instead of S_IFCHR In barebox, block devices are a special case of character devices. Nevertheless, differentiation can be useful to allow scripts iterating over all block devices without accounting for naming, e.g. for dev in /dev/*; do test -b $dev && echo $dev: blockdevice done Add the necessary support. This will break scripts that assume test -c blockdevice to be true, but that's a quite improbable check. Tested-by: Jules Maselbas Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220602195916.9061-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- commands/memtester/memtester.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commands') diff --git a/commands/memtester/memtester.c b/commands/memtester/memtester.c index 130dc97c83..f4adbfc855 100644 --- a/commands/memtester/memtester.c +++ b/commands/memtester/memtester.c @@ -113,7 +113,7 @@ static int do_memtester(int argc, char **argv) { strerror(errno)); return COMMAND_ERROR_USAGE; } else { - if (!S_ISCHR(statbuf.st_mode)) { + if (!S_ISCHR(statbuf.st_mode) && !S_ISBLK(statbuf.st_mode)) { printf("can not mmap non-char device %s\n", optarg); return COMMAND_ERROR_USAGE; -- cgit v1.2.1 From 870a96a80ba69f2e7d0312a84adecb70bd11ae4a Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Tue, 7 Jun 2022 08:19:57 +0300 Subject: treewide: Remove duplicate incudes Fix warning fwterated by checkincludes.pl: ./net/nfs.c: libgen.h is included more than once. ./net/ifup.c: globalvar.h is included more than once. ./crypto/rsa.c: asm/types.h is included more than once. ./lib/decompress_unlz4.c: linux/decompress/mm.h is included more than once. ./scripts/stb_image.h: stdio.h is included more than once. ./scripts/kwbimage.c: unistd.h is included more than once. ./scripts/common.c: sys/types.h is included more than once. ./scripts/bareboximd.c: sys/types.h is included more than once. ./scripts/bareboximd.c: sys/mman.h is included more than once. ./fs/pstore/ram_core.c: linux/rslib.h is included more than once. ./fs/pstore/fs.c: fs.h is included more than once. ./fs/pstore/fs.c: linux/pstore.h is included more than once. ./fs/nfs.c: fs.h is included more than once. ./fs/uimagefs.c: fs.h is included more than once. ./fs/fs.c: command.h is included more than once. ./arch/sandbox/board/hostfile.c: linux/err.h is included more than once. ./arch/sandbox/board/devices.c: mach/linux.h is included more than once. ./arch/sandbox/os/common.c: signal.h is included more than once. ./arch/arm/boards/zii-imx51-rdu1/board.c: envfs.h is included more than once. ./arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c: generated/mach-types.h is ./arch/arm/mach-stm32mp/ddrctrl.c: mach/stm32.h is included more than once. ./arch/arm/mach-imx/cpu_init.c: common.h is included more than once. ./arch/arm/mach-imx/imx8m.c: mach/imx8m-ccm-regs.h is included more than once. ./common/efi/payload/init.c: efi.h is included more than once. ./common/state/backend_format_raw.c: common.h is included more than once. ./common/state/backend_format_raw.c: crc.h is included more than once. ./common/hush.c: libbb.h is included more than once. ./drivers/spi/atmel-quadspi.c: linux/clk.h is included more than once. ./drivers/spi/atmel-quadspi.c: linux/err.h is included more than once. ./drivers/net/virtio.c: net.h is included more than once. ./drivers/net/phy/phy.c: linux/phy.h is included more than once. ./drivers/net/cpsw.c: net.h is included more than once. ./drivers/virtio/virtio_pci_common.h: linux/list.h is included more than once. ./drivers/usb/host/ohci-hcd.c: dma.h is included more than once. ./drivers/usb/gadget/fsl_udc.c: dma.h is included more than once. ./drivers/nvmem/eeprom_93xx46.c: spi/spi.h is included more than once. ./drivers/nvmem/eeprom_93xx46.c: of.h is included more than once. ./drivers/video/imx-ipu-v3/imx-ldb.c: linux/clk.h is included more than once. ./drivers/video/imx-ipu-v3/imx-hdmi.c: linux/clk.h is included more than once. ./drivers/video/omap.c: common.h is included more than once. ./drivers/mtd/nand/nand_s3c24xx.c: asm/sections.h is included more than once. ./drivers/clk/imx/clk-imx6sx.c: linux/clk.h is included more than once. ./drivers/clk/imx/clk-imx6sl.c: linux/clk.h is included more than once. ./commands/bootm.c: of.h is included more than once. Signed-off-by: Alexander Shiyan Link: https://lore.barebox.org/20220607051957.2497-1-eagle.alexander923@gmail.com Signed-off-by: Sascha Hauer --- commands/bootm.c | 1 - 1 file changed, 1 deletion(-) (limited to 'commands') diff --git a/commands/bootm.c b/commands/bootm.c index f54a4827eb..95d267135c 100644 --- a/commands/bootm.c +++ b/commands/bootm.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.1 From 85369d3b8d4ae31cacd77decbe5bcf01a90aeb3f Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Thu, 9 Jun 2022 10:26:29 +0300 Subject: read_file: Pass NULL for the size parameter if the return value is not used Signed-off-by: Alexander Shiyan Link: https://lore.barebox.org/20220609072629.15723-1-eagle.alexander923@gmail.com Signed-off-by: Sascha Hauer --- commands/spd_decode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'commands') diff --git a/commands/spd_decode.c b/commands/spd_decode.c index e8ee339a91..fa8fe86cf8 100644 --- a/commands/spd_decode.c +++ b/commands/spd_decode.c @@ -16,13 +16,12 @@ static int do_spd_decode(int argc, char *argv[]) { int ret; - size_t size; void *data; if (argc != 2) return COMMAND_ERROR_USAGE; - ret = read_file_2(argv[1], &size, &data, 256); + ret = read_file_2(argv[1], NULL, &data, 256); if (ret && ret != -EFBIG) { printf("unable to read %s: %s\n", argv[1], strerror(-ret)); return COMMAND_ERROR; -- cgit v1.2.1 From 58c7c027acc4ebf27ddd622001bafb596e8123cf Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 17 Jun 2022 10:04:34 +0200 Subject: treewide: Use pr_setenv() where appropriate We now have pr_setenv() which is a setenv() variant that takes a format string. Use it where appropriate. Signed-off-by: Sascha Hauer --- commands/clk.c | 10 +++------- commands/crc.c | 14 ++++---------- commands/hwclock.c | 4 +--- commands/loadb.c | 4 +--- commands/loads.c | 4 +--- 5 files changed, 10 insertions(+), 26 deletions(-) (limited to 'commands') diff --git a/commands/clk.c b/commands/clk.c index dfbc7c988f..b1741b9da4 100644 --- a/commands/clk.c +++ b/commands/clk.c @@ -139,13 +139,9 @@ static int do_clk_get_rate(int argc, char *argv[]) rate = clk_get_rate(clk); - if (variable_name) { - char *t; - - t = basprintf("%lu", rate); - setenv(variable_name, t); - free(t); - } else + if (variable_name) + pr_setenv(variable_name, "%lu", rate); + else printf("%lu\n", rate); return COMMAND_SUCCESS; diff --git a/commands/crc.c b/commands/crc.c index 80ecf7fe29..23ffd4360b 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -83,17 +83,11 @@ static int do_crc(int argc, char *argv[]) printf("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx", filename, (ulong)start, (ulong)start + total - 1, crc); - if (crcvarname) { - char *crcstr = basprintf("0x%lx", crc); - setenv(crcvarname, crcstr); - kfree(crcstr); - } + if (crcvarname) + pr_setenv(crcvarname, "0x%lx", crc); - if (sizevarname) { - char *sizestr = basprintf("0x%lx", total); - setenv(sizevarname, sizestr); - kfree(sizestr); - } + if (sizevarname) + pr_setenv(sizevarname, "0x%lx", total); #ifdef CONFIG_CMD_CRC_CMP if (vfilename) { diff --git a/commands/hwclock.c b/commands/hwclock.c index abb0500e6a..c594e070ac 100644 --- a/commands/hwclock.c +++ b/commands/hwclock.c @@ -153,11 +153,9 @@ static int do_hwclock(int argc, char *argv[]) if (env_name) { unsigned long time; - char t[12]; rtc_tm_to_time(&tm, &time); - snprintf(t, 12, "%lu", time); - setenv(env_name, t); + pr_setenv(env_name, "%lu", time); } else { printf("%s\n", time_str(&tm)); } diff --git a/commands/loadb.c b/commands/loadb.c index 17d3af84b5..7ab989f459 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -542,7 +542,6 @@ packet_error: static ulong load_serial_bin(void) { int size, i; - char buf[32]; /* Try to allocate the buffer we shall write to files */ write_buffer = malloc(MAX_WRITE_BUFFER); @@ -576,8 +575,7 @@ static ulong load_serial_bin(void) write_idx = 0; } printf("## Total Size = 0x%08x = %d Bytes\n", size, size); - sprintf(buf, "%X", size); - setenv("filesize", buf); + pr_setenv("filesize", "%X", size); err_quit: free(write_buffer); diff --git a/commands/loads.c b/commands/loads.c index 8260673c51..7c5df31251 100644 --- a/commands/loads.c +++ b/commands/loads.c @@ -65,7 +65,6 @@ static ulong load_serial(ulong offset) int type; /* return code for record type */ ulong addr; /* load address from S-Record */ ulong size; /* number of bytes transferred */ - char buf[32]; ulong store_addr; ulong start_addr = ~0; ulong end_addr = 0; @@ -100,8 +99,7 @@ static ulong load_serial(ulong offset) "## Total Size = 0x%08lX = %ld Bytes\n", start_addr, end_addr, size, size ); - sprintf(buf, "%lX", size); - setenv("filesize", buf); + pr_setenv("filesize", "%lX", size); return addr; case SREC_START: break; -- cgit v1.2.1 From ea162825a013c29823fed9e7d77c9671684cf247 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 20 Jun 2022 09:19:36 +0200 Subject: state: don't report error for -ENOMEDIUM Since commit 863a2251393e ("state: make first boot less verbose"), state_load returns -ENOMEDIUM instead of -ENOENT if we detect a first load because all buckets are zero. This case is expected and shouldn't warrant an error message, so adjust callers appropriately. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220620071936.1460295-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- commands/state.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'commands') diff --git a/commands/state.c b/commands/state.c index e7cb9902f7..56ef93b19f 100644 --- a/commands/state.c +++ b/commands/state.c @@ -53,6 +53,9 @@ static int do_state(int argc, char *argv[]) ret = state_save(state); } + if (ret == -ENOMEDIUM) + ret = 0; + return ret; } -- cgit v1.2.1