From patchwork Sat Feb 3 07:51:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13543936 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D1A74EB38; Sat, 3 Feb 2024 07:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706946752; cv=none; b=KUfpZo3hZVjGrSMhcNVjN1Jpi+LBY1PfH7m/g+zpyvMn9ZoJNLuNJ/H05MSzQNg1VlMxliuV0Dr3+iXYk2uZeA/37XOYL8pzME1JMDqwxin4PlJ4akluscqr6osOPe8G0P79Eap0r7jdDr/HFj0clkEwNt3KZnnTL4kb8E6gVeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706946752; c=relaxed/simple; bh=aObXlr/4PR6KuSz8tcT/d0388K6mphyDLXDR/dnQyDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJuBBqKJsTpX9A2Hz7HVbqQ/wN7nJndAHQhfA4IuTKSeN+RWZDHL0Yk11kvhBUmObnkZNQ5CDclyg2yJzpHGy64db40O/TP3b1b/YNb/GqM7rrRAxhnmqSgoTHUkrg2GcLnk2t6c5jkbkFGN9cP/EBLuFlyrCDT8ch/MXf3kx7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=kWneXtzT; arc=none smtp.client-ip=80.12.242.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="kWneXtzT" Received: from fedora.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id WAnwrvC6Ki8tRWAo5rII0H; Sat, 03 Feb 2024 08:51:21 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1706946681; bh=fjCBezS7CokH+7JLcr/hfWM+uGZ5cz/EMtWkOxCQIdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kWneXtzTmCFzOw/FUm8NnKkQd7Iw/IzgIyI9OnUrFuIkyCUysZBPxzSSHc7rCnzLp Fjo0vDrwv1+o0JQAK6tK7XJMUzCdZ2FJaNBDhFY7VqWZjSmQTcIkzexhjGiUyygQp5 iYTUCXnEUxtPItjc+7CG2+NFGh59KFIPKqTGGyKSNWiJwn2DtS1+BYrVRJhTl/3EnV X+gYEW8+s/BwowQ8bpVYMbXhj2rWc8ueMITbCV3FcgsJCKcaA94wP43ikE2KMFCE/r 2SboN1MQF6TknmG3CvtHW61z0kq5QVbiVkCQzCa3uZmCpzg3TczRjcY1OeWz5SINnA nhruBnB2ax0ig== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 03 Feb 2024 08:51:21 +0100 X-ME-IP: 92.140.202.140 From: Christophe JAILLET To: krzysztof.kozlowski@linaro.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication Date: Sat, 3 Feb 2024 08:51:03 +0100 Message-ID: <6d9a8544b923d92defdf2ab1b9092004cc7b51f1.1706946099.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add a new helper to avoid code duplication between nfc_llc_exit() and nfc_llc_unregister(). Signed-off-by: Christophe JAILLET Reviewed-by: Simon Horman --- net/nfc/hci/llc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c index 2140f6724644..480c17f372a5 100644 --- a/net/nfc/hci/llc.c +++ b/net/nfc/hci/llc.c @@ -30,15 +30,19 @@ int __init nfc_llc_init(void) return r; } +static void nfc_llc_del_engine(struct nfc_llc_engine *llc_engine) +{ + list_del(&llc_engine->entry); + kfree(llc_engine->name); + kfree(llc_engine); +} + void nfc_llc_exit(void) { struct nfc_llc_engine *llc_engine, *n; - list_for_each_entry_safe(llc_engine, n, &llc_engines, entry) { - list_del(&llc_engine->entry); - kfree(llc_engine->name); - kfree(llc_engine); - } + list_for_each_entry_safe(llc_engine, n, &llc_engines, entry) + nfc_llc_del_engine(llc_engine); } int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops) @@ -82,9 +86,7 @@ void nfc_llc_unregister(const char *name) if (llc_engine == NULL) return; - list_del(&llc_engine->entry); - kfree(llc_engine->name); - kfree(llc_engine); + nfc_llc_del_engine(llc_engine); } struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev, From patchwork Sat Feb 3 07:51:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13543935 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18CA24F5EA; Sat, 3 Feb 2024 07:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706946750; cv=none; b=KEVkGgv0T0kk4OCpCl8963q0BEa3rndETtRyBS6ZGuh+e0hO7ntIQz32NZQzYIFr2lCd4BsNgZwYuUwAFQxmGhuwfLAy5qJ/Kf500/JzDyKXLXZSZjpj1sdQdiHtBdnnPHtRHgyrO0KTGZFKVLlzkowK/eXIqVVpvqH25EwTiw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706946750; c=relaxed/simple; bh=haoge43Ne0oBEpD0h2wKsXPSAC+6OmzX0ZitPVb50po=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VUe8gLis0wbO5cnIVk1vofx9rue2i28BKEtY7+BtAIhqvS1XimI4ui3cJQYADNRhDT2+G3G4VfH6NqhHEbbIOzmd/srJcIDRkr3mK9AZcfe81FNyn3sEXkDk7Wr879uHSPF9QXOSA2kwjmQ37dpb6C44uS1MsqwrpRfR/AruVgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=U2lmYnlY; arc=none smtp.client-ip=80.12.242.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="U2lmYnlY" Received: from fedora.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id WAnwrvC6Ki8tRWAoBrII3V; Sat, 03 Feb 2024 08:51:27 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1706946687; bh=PvF+EwWrp7JXup44JQu6ssRQrUrUbuCCt5KLY27Imlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U2lmYnlYSmycEgBJXlN2kKc9yNONiBofVvUFCrMyqJeT6IAryWYlRMtj/4oueueNT yAbm+SA4Rw6NXIk5zwAIqm3mqWITyfjGJlGZ2YZlVknWGUPvwIQJBfBdFgH+wBEwEx OrRKvCWXcZ1VEG9qm+eF/wfYqYp2g6ps8915m9QYY3Y6rA6ER4vSguUXaZrGZuswoh /QsHpEIko+2L307vGAEv779FY+f9yFUTrNzuYzz61XUJc03Yvjc3yNN4wupoUSehwL 8iCkn8evBtX+Qp1WvTN/Ituv+u6jy8T+ECHVp40ZRNXTagK5Q716Z+PVHOLs9Ztyvs iJ/ivpPL7Qx+A== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 03 Feb 2024 08:51:27 +0100 X-ME-IP: 92.140.202.140 From: Christophe JAILLET To: krzysztof.kozlowski@linaro.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Date: Sat, 3 Feb 2024 08:51:04 +0100 Message-ID: <01cafe43646575d843ce81221ef4e0cdef6df84b.1706946099.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org nfc_llc_register() calls pass a string literal as the 'name' parameter. So kstrdup_const() can be used instead of kfree() to avoid a memory allocation in such cases. Signed-off-by: Christophe JAILLET Reviewed-by: Simon Horman --- net/nfc/hci/llc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c index 480c17f372a5..ba91284f4086 100644 --- a/net/nfc/hci/llc.c +++ b/net/nfc/hci/llc.c @@ -33,7 +33,7 @@ int __init nfc_llc_init(void) static void nfc_llc_del_engine(struct nfc_llc_engine *llc_engine) { list_del(&llc_engine->entry); - kfree(llc_engine->name); + kfree_const(llc_engine->name); kfree(llc_engine); } @@ -53,7 +53,7 @@ int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops) if (llc_engine == NULL) return -ENOMEM; - llc_engine->name = kstrdup(name, GFP_KERNEL); + llc_engine->name = kstrdup_const(name, GFP_KERNEL); if (llc_engine->name == NULL) { kfree(llc_engine); return -ENOMEM;