[PATCH v1 1/2] net/macb: add new driver
Stephen Hemminger
stephen at networkplumber.org
Sat Nov 2 06:43:10 CET 2024
On Fri, 1 Nov 2024 10:07:19 +0000
liwencheng <liwencheng at 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.
More information about the dev
mailing list