On Fri, 1 Nov 2024 10:07:19 +0000 liwencheng <liwench...@phytium.com.cn> wrote:
> +int macb_uio_init(const char *name, struct macb_iomem **iomem) > +{ > + struct macb_iomem *new; > + int ret; > + > + new = malloc(sizeof(struct macb_iomem)); > + if (!new) { > + MACB_LOG(ERR, "No memory for IOMEM obj."); > + return -ENOMEM; > + } > + memset(new, 0, sizeof(struct macb_iomem)); > + > + new->name = malloc(strlen(name) + 1); > + if (!new->name) { > + MACB_LOG(ERR, "No memory for IOMEM-name obj."); > + ret = -ENOMEM; > + goto out_free; > + } > + > + memcpy(new->name, name, strlen(name)); > + new->name[strlen(name)] = '\0'; This looks like you just reinvented strdup() function and did with calling strlen() multiple times.