Merge branch '2023-08-08-assorted-code-corrections' into next

- A number of code corrections caught by Smatch and a few others as
  well.
This commit is contained in:
Tom Rini 2023-08-08 21:38:05 -04:00
commit 1e1437d9f8
26 changed files with 51 additions and 53 deletions

View file

@ -104,8 +104,8 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
} }
/* Update PHY names (mandatory to disable USB3.0) */ /* Update PHY names (mandatory to disable USB3.0) */
len = strlcpy(data, "usb2-phy0", 32); len = strlcpy(data, "usb2-phy0", 32) + 1;
len += strlcpy(&data[len], "usb2-phy1", 32 - len); len += strlcpy(&data[len], "usb2-phy1", 32 - len) + 1;
ret = fdt_setprop(blob, node, "phy-names", data, len); ret = fdt_setprop(blob, node, "phy-names", data, len);
if (ret < 0) { if (ret < 0) {
printf("vim3: failed to update usb phy names property (%d)\n", ret); printf("vim3: failed to update usb phy names property (%d)\n", ret);
@ -132,7 +132,7 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
} }
/* Enable PCIe */ /* Enable PCIe */
len = strlcpy(data, "okay", 32); len = strlcpy(data, "okay", 32) + 1;
ret = fdt_setprop(blob, node, "status", data, len); ret = fdt_setprop(blob, node, "status", data, len);
if (ret < 0) { if (ret < 0) {
printf("vim3: failed to enable pcie node (%d)\n", ret); printf("vim3: failed to enable pcie node (%d)\n", ret);

View file

@ -33,7 +33,6 @@
#include <asm/arch/sys_proto.h> #include <asm/arch/sys_proto.h>
#include <asm/global_data.h> #include <asm/global_data.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <u-boot/crc.h>
#ifndef CONFIG_ARM64 #ifndef CONFIG_ARM64
#include <asm/armv7.h> #include <asm/armv7.h>
#endif #endif

View file

@ -12,7 +12,6 @@
#include <memalign.h> #include <memalign.h>
#include <linux/err.h> #include <linux/err.h>
#include <u-boot/crc.h> #include <u-boot/crc.h>
#include <u-boot/crc.h>
/** /**
* Compute the CRC-32 of the bootloader control struct. * Compute the CRC-32 of the bootloader control struct.

View file

@ -416,7 +416,7 @@ int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
if (!scene_obj_find(scn, label_id, SCENEOBJT_TEXT)) if (!scene_obj_find(scn, label_id, SCENEOBJT_TEXT))
return log_msg_ret("txt", -EINVAL); return log_msg_ret("txt", -EINVAL);
item = calloc(1, sizeof(struct scene_obj_menu)); item = calloc(1, sizeof(struct scene_menitem));
if (!item) if (!item)
return log_msg_ret("item", -ENOMEM); return log_msg_ret("item", -ENOMEM);
item->name = strdup(name); item->name = strdup(name);

View file

@ -49,7 +49,7 @@ static struct mux_control *cmd_mux_find(char *const argv[])
chip = dev_get_uclass_priv(dev); chip = dev_get_uclass_priv(dev);
if (!chip) if (!chip)
return ERR_PTR(ret); return ERR_PTR(-EINVAL);
if (id >= chip->controllers) if (id >= chip->controllers)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);

View file

@ -262,7 +262,7 @@ static int append_value(char **bufp, size_t *sizep, char *data)
char *tmp_buf = NULL, *new_buf = NULL, *value; char *tmp_buf = NULL, *new_buf = NULL, *value;
unsigned long len = 0; unsigned long len = 0;
if (!strncmp(data, "=0x", 2)) { /* hexadecimal number */ if (!strncmp(data, "=0x", 3)) { /* hexadecimal number */
union { union {
u8 u8; u8 u8;
u16 u16; u16 u16;

View file

@ -294,8 +294,8 @@ static int test_readonly(struct udevice *dev)
*/ */
index_0 += 1; index_0 += 1;
if (tpm_nv_write_value(dev, INDEX0, (uint8_t *)&index_0, if (tpm_nv_write_value(dev, INDEX0, (uint8_t *)&index_0,
sizeof(index_0) != sizeof(index_0)) !=
TPM_SUCCESS)) { TPM_SUCCESS) {
pr_err("\tcould not write index 0\n"); pr_err("\tcould not write index 0\n");
} }
tpm_nv_write_value_lock(dev, INDEX0); tpm_nv_write_value_lock(dev, INDEX0);

View file

@ -148,7 +148,8 @@ static int print_resetinfo(void)
bool status_printed = false; bool status_printed = false;
int ret; int ret;
/* Not all boards have sysreset drivers available during early /*
* Not all boards have sysreset drivers available during early
* boot, so don't fail if one can't be found. * boot, so don't fail if one can't be found.
*/ */
for (ret = uclass_first_device_check(UCLASS_SYSRESET, &dev); dev; for (ret = uclass_first_device_check(UCLASS_SYSRESET, &dev); dev;

View file

@ -21,7 +21,6 @@
#include <asm/global_data.h> #include <asm/global_data.h>
#include <asm/io.h> #include <asm/io.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <u-boot/crc.h>
#else #else
#include "mkimage.h" #include "mkimage.h"
#include <linux/compiler_attributes.h> #include <linux/compiler_attributes.h>

View file

@ -103,7 +103,7 @@ void *ofnode_lookup_fdt(ofnode node)
if (gd->flags & GD_FLG_RELOC) { if (gd->flags & GD_FLG_RELOC) {
uint i = OFTREE_TREE_ID(node.of_offset); uint i = OFTREE_TREE_ID(node.of_offset);
if (i > oftree_count) { if (i >= oftree_count) {
log_debug("Invalid tree ID %x\n", i); log_debug("Invalid tree ID %x\n", i);
return NULL; return NULL;
} }

View file

@ -183,7 +183,7 @@ static void __maybe_unused getvar_has_slot(char *part_name, char *response)
/* part_name_wslot = part_name + "_a" */ /* part_name_wslot = part_name + "_a" */
len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3); len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3);
if (len > PART_NAME_LEN - 3) if (len >= PART_NAME_LEN - 3)
goto fail; goto fail;
strcat(part_name_wslot, "_a"); strcat(part_name_wslot, "_a");

View file

@ -1100,8 +1100,11 @@ int cros_ec_get_sku_id(struct udevice *dev)
ret = ec_command_inptr(dev, EC_CMD_GET_SKU_ID, 0, NULL, 0, ret = ec_command_inptr(dev, EC_CMD_GET_SKU_ID, 0, NULL, 0,
(uint8_t **)&r, sizeof(*r)); (uint8_t **)&r, sizeof(*r));
if (ret != sizeof(*r)) if (ret != sizeof(*r)) {
return -ret; if (ret >= 0)
ret = -EIO;
return ret;
}
return r->sku_id; return r->sku_id;
} }

View file

@ -1446,7 +1446,7 @@ phys_addr_t dm_pci_bus_to_phys(struct udevice *dev, pci_addr_t bus_addr,
return res->phys_start + offset; return res->phys_start + offset;
} }
puts("pci_hose_bus_to_phys: invalid physical address\n"); puts("dm_pci_bus_to_phys: invalid physical address\n");
return 0; return 0;
} }
@ -1486,7 +1486,7 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,
return res->bus_start + offset; return res->bus_start + offset;
} }
puts("pci_hose_phys_to_bus: invalid physical address\n"); puts("dm_pci_phys_to_bus: invalid physical address\n");
return 0; return 0;
} }

View file

@ -689,7 +689,7 @@ static int alloc_vring(struct udevice *dev, struct fw_rsc_vdev *rsc, int i)
debug("alloc_mem(%#x, %d): %p\n", size, order, pa); debug("alloc_mem(%#x, %d): %p\n", size, order, pa);
vring->da = (uintptr_t)pa; vring->da = (uintptr_t)pa;
return !pa; return 0;
} }
static int handle_vdev(struct udevice *dev, struct fw_rsc_vdev *rsc, static int handle_vdev(struct udevice *dev, struct fw_rsc_vdev *rsc,

View file

@ -390,7 +390,7 @@ int btrfs_read_extent_inline(struct btrfs_path *path,
csize); csize);
ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi),
cbuf, csize, dbuf, dsize); cbuf, csize, dbuf, dsize);
if (ret == (u32)-1) { if (ret < 0) {
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
@ -500,7 +500,7 @@ int btrfs_read_extent_reg(struct btrfs_path *path,
ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), cbuf, ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi), cbuf,
csize, dbuf, dsize); csize, dbuf, dsize);
if (ret == (u32)-1) { if (ret < 0) {
ret = -EIO; ret = -EIO;
goto out; goto out;
} }

View file

@ -199,6 +199,7 @@ static int list_subvolums(struct btrfs_fs_info *fs_info)
ret = PTR_ERR(root); ret = PTR_ERR(root);
if (ret == -ENOENT) if (ret == -ENOENT)
goto next; goto next;
goto out;
} }
ret = list_one_subvol(root, result); ret = list_one_subvol(root, result);
if (ret < 0) if (ret < 0)

View file

@ -166,8 +166,7 @@ static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
unsigned long ret; unsigned long ret;
char *link; char *link;
if (p && strlen(p)) { if (p && strlen(p)) {
printf ("unsupported symlink to \ printf ("unsupported symlink to non-terminal path\n");
non-terminal path\n");
return 0; return 0;
} }
link = cramfs_uncompress_link (begin, link = cramfs_uncompress_link (begin,
@ -177,8 +176,7 @@ static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
namelen, namelen, name); namelen, namelen, name);
return 0; return 0;
} else if (link[0] == '/') { } else if (link[0] == '/') {
printf ("unsupported symlink to \ printf ("unsupported symlink to absolute path\n");
absolute path\n");
free (link); free (link);
return 0; return 0;
} }

View file

@ -58,7 +58,7 @@ enum video_log2_bpp {
* Convert enum video_log2_bpp to bytes and bits. Note we omit the outer * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
* brackets to allow multiplication by fractional pixels. * brackets to allow multiplication by fractional pixels.
*/ */
#define VNBYTES(bpix) (1 << (bpix)) / 8 #define VNBYTES(bpix) ((1 << (bpix)) / 8)
#define VNBITS(bpix) (1 << (bpix)) #define VNBITS(bpix) (1 << (bpix))

View file

@ -444,14 +444,14 @@ u16 *u16_strdup(const void *src)
size_t u16_strlcat(u16 *dest, const u16 *src, size_t count) size_t u16_strlcat(u16 *dest, const u16 *src, size_t count)
{ {
size_t destlen = u16_strlen(dest); size_t destlen = u16_strnlen(dest, count);
size_t srclen = u16_strlen(src); size_t srclen = u16_strlen(src);
size_t ret = destlen + srclen + 1; size_t ret = destlen + srclen;
if (destlen >= count) if (destlen >= count)
return ret; return ret;
if (ret > count) if (ret >= count)
srclen -= ret - count; srclen -= (ret - count + 1);
memcpy(&dest[destlen], src, 2 * srclen); memcpy(&dest[destlen], src, 2 * srclen);
dest[destlen + srclen] = 0x0000; dest[destlen + srclen] = 0x0000;

View file

@ -10,7 +10,6 @@
#ifdef USE_HOSTCC #ifdef USE_HOSTCC
#include <arpa/inet.h> #include <arpa/inet.h>
#include <u-boot/crc.h>
#else #else
#include <common.h> #include <common.h>
#include <efi_loader.h> #include <efi_loader.h>

View file

@ -116,20 +116,18 @@ char * strncpy(char * dest,const char *src,size_t count)
* of course, the buffer size is zero). It does not pad * of course, the buffer size is zero). It does not pad
* out the result like strncpy() does. * out the result like strncpy() does.
* *
* Return: the number of bytes copied * Return: strlen(src)
*/ */
size_t strlcpy(char *dest, const char *src, size_t size) size_t strlcpy(char *dest, const char *src, size_t size)
{ {
if (size) { size_t ret = strlen(src);
size_t srclen = strlen(src);
size_t len = (srclen >= size) ? size - 1 : srclen;
if (size) {
size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len); memcpy(dest, src, len);
dest[len] = '\0'; dest[len] = '\0';
return len + 1;
} }
return ret;
return 0;
} }
#endif #endif
@ -191,6 +189,8 @@ char * strncat(char *dest, const char *src, size_t count)
* Compatible with *BSD: the result is always a valid NUL-terminated string that * Compatible with *BSD: the result is always a valid NUL-terminated string that
* fits in the buffer (unless, of course, the buffer size is zero). It does not * fits in the buffer (unless, of course, the buffer size is zero). It does not
* write past @size like strncat() does. * write past @size like strncat() does.
*
* Return: min(strlen(dest), size) + strlen(src)
*/ */
size_t strlcat(char *dest, const char *src, size_t size) size_t strlcat(char *dest, const char *src, size_t size)
{ {

View file

@ -120,7 +120,7 @@ static int lib_asn1_x509(struct unit_test_state *uts)
cert = x509_cert_parse(cert_data, cert_data_len); cert = x509_cert_parse(cert_data, cert_data_len);
ut_assertf(cert != NULL, "decoding failed\n"); ut_assertf(!IS_ERR(cert), "decoding failed\n");
ut_assertf(!strcmp(cert->subject, "Linaro: Tester"), ut_assertf(!strcmp(cert->subject, "Linaro: Tester"),
"subject doesn't match\n"); "subject doesn't match\n");
ut_assertf(!strcmp(cert->issuer, "Linaro: Tester"), ut_assertf(!strcmp(cert->issuer, "Linaro: Tester"),
@ -313,7 +313,7 @@ static int lib_asn1_pkcs7(struct unit_test_state *uts)
pkcs7 = pkcs7_parse_message(image_pk7, image_pk7_len); pkcs7 = pkcs7_parse_message(image_pk7, image_pk7_len);
ut_assertf(pkcs7 != NULL, "decoding failed\n"); ut_assertf(!IS_ERR(pkcs7), "decoding failed\n");
ut_assertf(pkcs7->data_len == 104, "signature size doesn't match\n"); ut_assertf(pkcs7->data_len == 104, "signature size doesn't match\n");
ut_assertf(pkcs7->signed_infos != NULL, "sign-info doesn't exist\n"); ut_assertf(pkcs7->signed_infos != NULL, "sign-info doesn't exist\n");
ut_assertf(pkcs7->signed_infos->msgdigest_len == 32, ut_assertf(pkcs7->signed_infos->msgdigest_len == 32,

View file

@ -43,11 +43,11 @@ static int do_test_strlcat(struct unit_test_state *uts, int line, size_t align1,
s2[i] = 32 + 23 * i % (127 - 32); s2[i] = 32 + 23 * i % (127 - 32);
s2[len2 - 1] = '\0'; s2[len2 - 1] = '\0';
expected = len2 < n ? min(len1 + len2 - 1, n) : n; expected = min(strlen(s2), n) + strlen(s1);
actual = strlcat(s2, s1, n); actual = strlcat(s2, s1, n);
if (expected != actual) { if (expected != actual) {
ut_failf(uts, __FILE__, line, __func__, ut_failf(uts, __FILE__, line, __func__,
"strlcat(s2, s1, 2) == len2 < n ? min(len1 + len2, n) : n", "strlcat(s2, s1, n) == min(len2, n) + len1",
"Expected %#zx (%zd), got %#zx (%zd)", "Expected %#zx (%zd), got %#zx (%zd)",
expected, expected, actual, actual); expected, expected, actual, actual);
return CMD_RET_FAILURE; return CMD_RET_FAILURE;

View file

@ -807,28 +807,28 @@ static int unicode_test_u16_strlcat(struct unit_test_state *uts)
/* dest and src are empty string */ /* dest and src are empty string */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = u16_strlcat(buf, &null_src, sizeof(buf)); ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf));
ut_asserteq(1, ret); ut_asserteq(0, ret);
/* dest is empty string */ /* dest is empty string */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
ret = u16_strlcat(buf, src, sizeof(buf)); ret = u16_strlcat(buf, src, ARRAY_SIZE(buf));
ut_asserteq(5, ret); ut_asserteq(4, ret);
ut_assert(!unicode_test_u16_strcmp(buf, src, 40)); ut_assert(!unicode_test_u16_strcmp(buf, src, 40));
/* src is empty string */ /* src is empty string */
memset(buf, 0xCD, (sizeof(buf) - sizeof(u16))); memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
buf[39] = 0; buf[39] = 0;
memcpy(buf, dest, sizeof(dest)); memcpy(buf, dest, sizeof(dest));
ret = u16_strlcat(buf, &null_src, sizeof(buf)); ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf));
ut_asserteq(6, ret); ut_asserteq(5, ret);
ut_assert(!unicode_test_u16_strcmp(buf, dest, 40)); ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
for (i = 0; i <= 40; i++) { for (i = 0; i <= 40; i++) {
memset(buf, 0xCD, (sizeof(buf) - sizeof(u16))); memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
buf[39] = 0; buf[39] = 0;
memcpy(buf, dest, sizeof(dest)); memcpy(buf, dest, sizeof(dest));
expected = 10; expected = min(5, i) + 4;
ret = u16_strlcat(buf, src, i); ret = u16_strlcat(buf, src, i);
ut_asserteq(expected, ret); ut_asserteq(expected, ret);
if (i <= 6) { if (i <= 6) {

View file

@ -15,7 +15,6 @@
#include "imagetool.h" #include "imagetool.h"
#include "mkimage.h" #include "mkimage.h"
#include <u-boot/crc.h>
#include <image.h> #include <image.h>
#include <tee/optee.h> #include <tee/optee.h>