From nobody Fri Jun 02 08:20:04 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QXbXN5QrHz4Yy6c; Fri, 2 Jun 2023 08:20:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QXbXN4hvCz3DV6; Fri, 2 Jun 2023 08:20:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685694004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oWnLij4wY973/g1/JJFMLwIVCLUbO1Y9sw4ycMTyPLI=; b=T/X3wZB26wcgfKrNwhipXeX/yKv/Rd23m/Vg/V62g3+rRMwhbAn/Q50E8MCpdfUIQIwNDk zMmm4EP+XlEJTcD3S8O3Y9rSrGyXiSh6+qHIKa9CiU/erUBnI/nDLBimsHiq98SYd/071l yub2G0s6vgfAv92u2cRWuBNmq8oNRZY6ziBGQ+QBfpzM1N9+rw00aAcZ2qKXk0oUuyh47f HauAOGxXk9AkhI4Uwo/5/JBCHBGvDlnBEFXGoXEXQQVdJjfoZMbPt1kEskFt5gxS7Z4/WM Tee02pivnNCi/aMAo2RS833vqgozuvLIUJsNKQMHjdMe22Y4ZYbnvXAQsIQfzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685694004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oWnLij4wY973/g1/JJFMLwIVCLUbO1Y9sw4ycMTyPLI=; b=F4O7AhmGGRSUAuNYEEA/BuOAZfW6gzU5aSSYXuofM10kcs59YXC9naEjiEr3GrvEH4wEpr ShDfebzc4ngkJAN1fMd4l3o2YXHdv6K3QtWg55qlyCC4xHc+dewVlS/jGI4UHfCG9orw4t XKqr5kK9rCrcPFQ9K5vVEE1xY/0BjAxR/HM6afMv+5VENyrEK+eLMCdlopFMbnMKY2vwkx orUnPI1TA4COgf98G6+WeWhhUKveEqkIDR3aDgZe+moTU+KfnS6BPgJIpvPQoKMTiloOuS EGq9y0lUBrU+I2p9ss14DUzMIW6DUl8hxSCAp7O57cg212SvHKFuTClFL5aRyQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685694004; a=rsa-sha256; cv=none; b=u9BuVHCpamOiWTkqhN0LIDIkr2KCCdNVDFM6Ze4SPEYei+Amvzo3RBi02AT+2IKQ9YhFvt fMaYVNYPbUYp7Txdp1ZpvfCZNRjgf+O4V7A5xqrxpY2SjZsN4G+5C1ZPCeQ2WnJKLlOhVV cgbcOeUJh20qNdLluo5Cnse8dvDbWXOFO6Xf7QdcdStultcNQfg+bjzsFqrlGTAhx50ijl AOiuhkunbfPUioMsr91t60Q2Do+HjoMlp3C/Fb6GeES5Ba9J8KZZXN8qnjJC0Ei86H2qd9 0qagdz4Tp+uzwQezALDXHccqTtCkltx3/tkE0h8S3IJTjgjLsadCEN0J2SklGQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QXbXN3S6yzrsb; Fri, 2 Jun 2023 08:20:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 3528K4xe071913; Fri, 2 Jun 2023 08:20:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3528K4X8071911; Fri, 2 Jun 2023 08:20:04 GMT (envelope-from git) Date: Fri, 2 Jun 2023 08:20:04 GMT Message-Id: <202306020820.3528K4X8071911@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 0bcb3ebd1fb7 - main - nlsysevent: deduplicate the code and split into smaller functions List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0bcb3ebd1fb71f397f020d30e6c087d2831fd72e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=0bcb3ebd1fb71f397f020d30e6c087d2831fd72e commit 0bcb3ebd1fb71f397f020d30e6c087d2831fd72e Author: Baptiste Daroussin AuthorDate: 2023-06-02 08:19:27 +0000 Commit: Baptiste Daroussin CommitDate: 2023-06-02 08:19:27 +0000 nlsysevent: deduplicate the code and split into smaller functions No functional changes intended Suggested by: melifaro --- sys/netlink/netlink_sysevent.c | 43 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/sys/netlink/netlink_sysevent.c b/sys/netlink/netlink_sysevent.c index 7bb783f7019c..aeb819e6e85d 100644 --- a/sys/netlink/netlink_sysevent.c +++ b/sys/netlink/netlink_sysevent.c @@ -86,27 +86,41 @@ sysevent_write(struct sysevent_group *se, const char *subsystem, const char *typ } static void -sysevent_send(const char *system, const char *subsystem, const char *type, - const char *data) +sysevent_new_group(size_t index, const char *name) { - struct sysevent_group *se = NULL; + if (index >= MAX_SYSEVENT_GROUPS) { + NL_LOG(LOG_WARNING, "impossible to add the event %s, " + "too many event groups\n", name); + return; + } + sysevent_groups[index].name = strdup(name, M_NLSE); + sysevent_groups[index].id = genl_register_group(NLSE_FAMILY_NAME, sysevent_groups[index].name); +} +static struct sysevent_group * +sysevent_get_group(const char *system) +{ for (size_t i = 0; i < MAX_SYSEVENT_GROUPS; i++) { if (sysevent_groups[i].name == NULL) { - sysevent_groups[i].name = strdup(system, M_NLSE); - sysevent_groups[i].id = genl_register_group(NLSE_FAMILY_NAME, - system); - se = &sysevent_groups[i]; - break; - } - if (strcmp(sysevent_groups[i].name, system) == 0) { - se = &sysevent_groups[i]; - break; + sysevent_new_group(i, system); + return (&sysevent_groups[i]); } + if (strcmp(sysevent_groups[i].name, system) == 0) + return (&sysevent_groups[i]); } + + return (NULL); +} + +static void +sysevent_send(const char *system, const char *subsystem, const char *type, + const char *data) +{ + struct sysevent_group *se = sysevent_get_group(system); + if (se == NULL) { NL_LOG(LOG_WARNING, "impossible to add the event %s, " - "too many events\n", system); + "too many event groups\n", system); return; } @@ -125,8 +139,7 @@ nlsysevent_load(void) NL_LOG(LOG_WARNING, "impossible to add the event %s, too many events\n", devctl_systems[i]); continue; } - sysevent_groups[i].name = strdup(devctl_systems[i], M_NLSE); - sysevent_groups[i].id = genl_register_group(NLSE_FAMILY_NAME, devctl_systems[i]); + sysevent_new_group(i, devctl_systems[i]); } }