mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 07:04:28 +00:00
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:
commit
1e1437d9f8
26 changed files with 51 additions and 53 deletions
|
@ -104,8 +104,8 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
|
|||
}
|
||||
|
||||
/* Update PHY names (mandatory to disable USB3.0) */
|
||||
len = strlcpy(data, "usb2-phy0", 32);
|
||||
len += strlcpy(&data[len], "usb2-phy1", 32 - len);
|
||||
len = strlcpy(data, "usb2-phy0", 32) + 1;
|
||||
len += strlcpy(&data[len], "usb2-phy1", 32 - len) + 1;
|
||||
ret = fdt_setprop(blob, node, "phy-names", data, len);
|
||||
if (ret < 0) {
|
||||
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 */
|
||||
len = strlcpy(data, "okay", 32);
|
||||
len = strlcpy(data, "okay", 32) + 1;
|
||||
ret = fdt_setprop(blob, node, "status", data, len);
|
||||
if (ret < 0) {
|
||||
printf("vim3: failed to enable pcie node (%d)\n", ret);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <asm/arch/sys_proto.h>
|
||||
#include <asm/global_data.h>
|
||||
#include <linux/delay.h>
|
||||
#include <u-boot/crc.h>
|
||||
#ifndef CONFIG_ARM64
|
||||
#include <asm/armv7.h>
|
||||
#endif
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <memalign.h>
|
||||
#include <linux/err.h>
|
||||
#include <u-boot/crc.h>
|
||||
#include <u-boot/crc.h>
|
||||
|
||||
/**
|
||||
* Compute the CRC-32 of the bootloader control struct.
|
||||
|
|
|
@ -702,8 +702,8 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
|
|||
}
|
||||
}
|
||||
|
||||
if (label->kaslrseed)
|
||||
label_boot_kaslrseed();
|
||||
if (label->kaslrseed)
|
||||
label_boot_kaslrseed();
|
||||
|
||||
#ifdef CONFIG_OF_LIBFDT_OVERLAY
|
||||
if (label->fdtoverlays)
|
||||
|
|
|
@ -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))
|
||||
return log_msg_ret("txt", -EINVAL);
|
||||
|
||||
item = calloc(1, sizeof(struct scene_obj_menu));
|
||||
item = calloc(1, sizeof(struct scene_menitem));
|
||||
if (!item)
|
||||
return log_msg_ret("item", -ENOMEM);
|
||||
item->name = strdup(name);
|
||||
|
|
|
@ -49,7 +49,7 @@ static struct mux_control *cmd_mux_find(char *const argv[])
|
|||
|
||||
chip = dev_get_uclass_priv(dev);
|
||||
if (!chip)
|
||||
return ERR_PTR(ret);
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (id >= chip->controllers)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
|
|
@ -262,7 +262,7 @@ static int append_value(char **bufp, size_t *sizep, char *data)
|
|||
char *tmp_buf = NULL, *new_buf = NULL, *value;
|
||||
unsigned long len = 0;
|
||||
|
||||
if (!strncmp(data, "=0x", 2)) { /* hexadecimal number */
|
||||
if (!strncmp(data, "=0x", 3)) { /* hexadecimal number */
|
||||
union {
|
||||
u8 u8;
|
||||
u16 u16;
|
||||
|
|
|
@ -294,8 +294,8 @@ static int test_readonly(struct udevice *dev)
|
|||
*/
|
||||
index_0 += 1;
|
||||
if (tpm_nv_write_value(dev, INDEX0, (uint8_t *)&index_0,
|
||||
sizeof(index_0) !=
|
||||
TPM_SUCCESS)) {
|
||||
sizeof(index_0)) !=
|
||||
TPM_SUCCESS) {
|
||||
pr_err("\tcould not write index 0\n");
|
||||
}
|
||||
tpm_nv_write_value_lock(dev, INDEX0);
|
||||
|
|
|
@ -148,11 +148,12 @@ static int print_resetinfo(void)
|
|||
bool status_printed = false;
|
||||
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.
|
||||
*/
|
||||
for (ret = uclass_first_device_check(UCLASS_SYSRESET, &dev); dev;
|
||||
ret = uclass_next_device_check(&dev)) {
|
||||
ret = uclass_next_device_check(&dev)) {
|
||||
if (ret) {
|
||||
debug("%s: %s sysreset device (error: %d)\n",
|
||||
__func__, dev->name, ret);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <asm/global_data.h>
|
||||
#include <asm/io.h>
|
||||
#include <linux/errno.h>
|
||||
#include <u-boot/crc.h>
|
||||
#else
|
||||
#include "mkimage.h"
|
||||
#include <linux/compiler_attributes.h>
|
||||
|
|
|
@ -103,7 +103,7 @@ void *ofnode_lookup_fdt(ofnode node)
|
|||
if (gd->flags & GD_FLG_RELOC) {
|
||||
uint i = OFTREE_TREE_ID(node.of_offset);
|
||||
|
||||
if (i > oftree_count) {
|
||||
if (i >= oftree_count) {
|
||||
log_debug("Invalid tree ID %x\n", i);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ static void __maybe_unused getvar_has_slot(char *part_name, char *response)
|
|||
|
||||
/* part_name_wslot = part_name + "_a" */
|
||||
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;
|
||||
strcat(part_name_wslot, "_a");
|
||||
|
||||
|
|
|
@ -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,
|
||||
(uint8_t **)&r, sizeof(*r));
|
||||
if (ret != sizeof(*r))
|
||||
return -ret;
|
||||
if (ret != sizeof(*r)) {
|
||||
if (ret >= 0)
|
||||
ret = -EIO;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return r->sku_id;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
puts("pci_hose_bus_to_phys: invalid physical address\n");
|
||||
puts("dm_pci_bus_to_phys: invalid physical address\n");
|
||||
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;
|
||||
}
|
||||
|
||||
puts("pci_hose_phys_to_bus: invalid physical address\n");
|
||||
puts("dm_pci_phys_to_bus: invalid physical address\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
vring->da = (uintptr_t)pa;
|
||||
|
||||
return !pa;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_vdev(struct udevice *dev, struct fw_rsc_vdev *rsc,
|
||||
|
|
|
@ -390,7 +390,7 @@ int btrfs_read_extent_inline(struct btrfs_path *path,
|
|||
csize);
|
||||
ret = btrfs_decompress(btrfs_file_extent_compression(leaf, fi),
|
||||
cbuf, csize, dbuf, dsize);
|
||||
if (ret == (u32)-1) {
|
||||
if (ret < 0) {
|
||||
ret = -EIO;
|
||||
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,
|
||||
csize, dbuf, dsize);
|
||||
if (ret == (u32)-1) {
|
||||
if (ret < 0) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
|
|
|
@ -199,6 +199,7 @@ static int list_subvolums(struct btrfs_fs_info *fs_info)
|
|||
ret = PTR_ERR(root);
|
||||
if (ret == -ENOENT)
|
||||
goto next;
|
||||
goto out;
|
||||
}
|
||||
ret = list_one_subvol(root, result);
|
||||
if (ret < 0)
|
||||
|
|
|
@ -166,8 +166,7 @@ static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
|
|||
unsigned long ret;
|
||||
char *link;
|
||||
if (p && strlen(p)) {
|
||||
printf ("unsupported symlink to \
|
||||
non-terminal path\n");
|
||||
printf ("unsupported symlink to non-terminal path\n");
|
||||
return 0;
|
||||
}
|
||||
link = cramfs_uncompress_link (begin,
|
||||
|
@ -177,8 +176,7 @@ static unsigned long cramfs_resolve (unsigned long begin, unsigned long offset,
|
|||
namelen, namelen, name);
|
||||
return 0;
|
||||
} else if (link[0] == '/') {
|
||||
printf ("unsupported symlink to \
|
||||
absolute path\n");
|
||||
printf ("unsupported symlink to absolute path\n");
|
||||
free (link);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ enum video_log2_bpp {
|
|||
* Convert enum video_log2_bpp to bytes and bits. Note we omit the outer
|
||||
* brackets to allow multiplication by fractional pixels.
|
||||
*/
|
||||
#define VNBYTES(bpix) (1 << (bpix)) / 8
|
||||
#define VNBYTES(bpix) ((1 << (bpix)) / 8)
|
||||
|
||||
#define VNBITS(bpix) (1 << (bpix))
|
||||
|
||||
|
|
|
@ -444,14 +444,14 @@ u16 *u16_strdup(const void *src)
|
|||
|
||||
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 ret = destlen + srclen + 1;
|
||||
size_t ret = destlen + srclen;
|
||||
|
||||
if (destlen >= count)
|
||||
return ret;
|
||||
if (ret > count)
|
||||
srclen -= ret - count;
|
||||
if (ret >= count)
|
||||
srclen -= (ret - count + 1);
|
||||
memcpy(&dest[destlen], src, 2 * srclen);
|
||||
dest[destlen + srclen] = 0x0000;
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#ifdef USE_HOSTCC
|
||||
#include <arpa/inet.h>
|
||||
#include <u-boot/crc.h>
|
||||
#else
|
||||
#include <common.h>
|
||||
#include <efi_loader.h>
|
||||
|
|
14
lib/string.c
14
lib/string.c
|
@ -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
|
||||
* 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)
|
||||
{
|
||||
if (size) {
|
||||
size_t srclen = strlen(src);
|
||||
size_t len = (srclen >= size) ? size - 1 : srclen;
|
||||
size_t ret = strlen(src);
|
||||
|
||||
if (size) {
|
||||
size_t len = (ret >= size) ? size - 1 : ret;
|
||||
memcpy(dest, src, len);
|
||||
dest[len] = '\0';
|
||||
return len + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
#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
|
||||
* fits in the buffer (unless, of course, the buffer size is zero). It does not
|
||||
* write past @size like strncat() does.
|
||||
*
|
||||
* Return: min(strlen(dest), size) + strlen(src)
|
||||
*/
|
||||
size_t strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
|
|
|
@ -120,7 +120,7 @@ static int lib_asn1_x509(struct unit_test_state *uts)
|
|||
|
||||
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"),
|
||||
"subject doesn't match\n");
|
||||
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);
|
||||
|
||||
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->signed_infos != NULL, "sign-info doesn't exist\n");
|
||||
ut_assertf(pkcs7->signed_infos->msgdigest_len == 32,
|
||||
|
|
|
@ -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[len2 - 1] = '\0';
|
||||
|
||||
expected = len2 < n ? min(len1 + len2 - 1, n) : n;
|
||||
expected = min(strlen(s2), n) + strlen(s1);
|
||||
actual = strlcat(s2, s1, n);
|
||||
if (expected != actual) {
|
||||
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, expected, actual, actual);
|
||||
return CMD_RET_FAILURE;
|
||||
|
|
|
@ -807,28 +807,28 @@ static int unicode_test_u16_strlcat(struct unit_test_state *uts)
|
|||
|
||||
/* dest and src are empty string */
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ret = u16_strlcat(buf, &null_src, sizeof(buf));
|
||||
ut_asserteq(1, ret);
|
||||
ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf));
|
||||
ut_asserteq(0, ret);
|
||||
|
||||
/* dest is empty string */
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ret = u16_strlcat(buf, src, sizeof(buf));
|
||||
ut_asserteq(5, ret);
|
||||
ret = u16_strlcat(buf, src, ARRAY_SIZE(buf));
|
||||
ut_asserteq(4, ret);
|
||||
ut_assert(!unicode_test_u16_strcmp(buf, src, 40));
|
||||
|
||||
/* src is empty string */
|
||||
memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
|
||||
buf[39] = 0;
|
||||
memcpy(buf, dest, sizeof(dest));
|
||||
ret = u16_strlcat(buf, &null_src, sizeof(buf));
|
||||
ut_asserteq(6, ret);
|
||||
ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf));
|
||||
ut_asserteq(5, ret);
|
||||
ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
|
||||
|
||||
for (i = 0; i <= 40; i++) {
|
||||
memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
|
||||
buf[39] = 0;
|
||||
memcpy(buf, dest, sizeof(dest));
|
||||
expected = 10;
|
||||
expected = min(5, i) + 4;
|
||||
ret = u16_strlcat(buf, src, i);
|
||||
ut_asserteq(expected, ret);
|
||||
if (i <= 6) {
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "imagetool.h"
|
||||
#include "mkimage.h"
|
||||
#include <u-boot/crc.h>
|
||||
|
||||
#include <image.h>
|
||||
#include <tee/optee.h>
|
||||
|
|
Loading…
Reference in a new issue