From patchwork Mon Oct 30 13:27:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 159740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2211280vqb; Mon, 30 Oct 2023 06:27:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkxE5Inebq7RCGrb6kQ9tQ60yTe2Lkp6niTIjHiBQaVKhgBGYwUOn9ZzwEHqZbNfifWIsM X-Received: by 2002:a17:90b:814:b0:27d:1369:515e with SMTP id bk20-20020a17090b081400b0027d1369515emr11986254pjb.22.1698672475181; Mon, 30 Oct 2023 06:27:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698672475; cv=none; d=google.com; s=arc-20160816; b=XAkWgqzTHH05MQZtnZZUHncjyJoqreH+SBiMpD36cvA3OTdkG+0j10KtXxC6+dn1qw 2OvBj/VM8zcDqlsbztW361SS9+Jl3sRearBNe5A+0fxfA/bUABkbQJ7YmYVWipEos4e8 gsIB7jk+tsyUsCreWvKhFeQjNA7di6bJOzwOS2ylrmYPtM/ksQy1T+mpTufsvjBTYqds ElIEYPO4C9INOsfNxWGowrc3swJbJFPWi8wRjDSOwTnFilxefbgbFo6FGNNvpaJrBKfa AQhy6M/IGl00vAyIVQ1dD7oyDpbGaeRR8CKcU2+yDpCA3XpyOxyuVsVagzBJ5xA/2fvV 4A6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/DkN5aD3T5Ca9TtQI/yHLRzDeLFOsujUxsYE2YCrNlU=; fh=kNnUXTBzA9YFHVXcKONYgP+0AIjxVaAgiwiYKqtJBMg=; b=DTs+ISFEom0+2+LqbB4mvy9cQh0zXYoco1C1pfKRXAa3Vgzs76ZmhtryG1EB1xWbSA wL+2RM4CPS6y5cFZ5Q6PzFrlbPTf6IQTbcFBjTG7dBS6Z1dMMGoTTT3BLDFLhTqYyAnB uPs6geaqDmQkdmPJX4Hiy7L+ioM1EhQrLQhueRRZ2NV6LkLtOsRYvcwqCph1Mtn0UyVn EFxmG2Z/4SEi+Iy3g1g3xrEytYb+eQbH7RZaYOML3VV8U5Osy3C6gQ/+SH/F7uGjandD URpRypU3B61/kCEerliBfncXrIxzGvo+7IvC6oT0EXXjH8u2jfplGx6LW+4lF0tSaQls RjCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=G7g6nIpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id a5-20020a17090a740500b0026d6ad52473si3909043pjg.34.2023.10.30.06.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:27:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=G7g6nIpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B97C180309D7; Mon, 30 Oct 2023 06:27:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233389AbjJ3N1n (ORCPT + 31 others); Mon, 30 Oct 2023 09:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbjJ3N1l (ORCPT ); Mon, 30 Oct 2023 09:27:41 -0400 Received: from smtp.smtpout.orange.fr (smtp-22.smtpout.orange.fr [80.12.242.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FE797 for ; Mon, 30 Oct 2023 06:27:37 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id xSIoq4DJYLilFxSIpqpweO; Mon, 30 Oct 2023 14:27:35 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698672455; bh=/DkN5aD3T5Ca9TtQI/yHLRzDeLFOsujUxsYE2YCrNlU=; h=From:To:Cc:Subject:Date; b=G7g6nIpo2eAt6Fz7quD13L6Gm0WeEBDbpvi0RJGBjXKcpZ/DjQCWzwqv1Gl94Ny3h 2idDLo5gCuCq53k/KKKiHBbbfY7iDz8q27xlbLOO14yiW+GsHza75cm1yx5yOw1Ao6 ibW7+WoTLu+LEh2x+VLRI4CbFOe4vC573ziiA9w3TVvjK/DDSEO2RNHU+2tSMdwiP6 C9VIbwhQ4ild3H21VcKgM35kPS1bHYQfHJ9tydWYUTMJrpxSUvV3W/Moak3qPuXLHN FTkIQ6QrqnE1P5INGirV7puw3fhCYpZtInVGoB9xzjZVEMEEHuDC6ibJXK2v4pPf+n t/m2nhemHB+Pw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 30 Oct 2023 14:27:35 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Tyler Hicks Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , ecryptfs@vger.kernel.org Subject: [PATCH] ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name() Date: Mon, 30 Oct 2023 14:27:32 +0100 Message-Id: <2c4bd387e8036854d3338400038fdde8dce3806a.1698672391.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 06:27:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781187189487530498 X-GMAIL-MSGID: 1781187189487530498 Use kasprintf() instead of hand writing it. It is much less verbose. Signed-off-by: Christophe JAILLET Reviewed-by: Dan Carpenter --- fs/ecryptfs/crypto.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 044863c0d824..00d795658cf5 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "ecryptfs_kernel.h" @@ -78,22 +79,12 @@ static int ecryptfs_crypto_api_algify_cipher_name(char **algified_name, char *cipher_name, char *chaining_modifier) { - int cipher_name_len = strlen(cipher_name); - int chaining_modifier_len = strlen(chaining_modifier); - int algified_name_len; - int rc; + *algified_name = kasprintf(GFP_KERNEL, "%s(%s)", + chaining_modifier, cipher_name); + if (!(*algified_name)) + return -ENOMEM; - algified_name_len = (chaining_modifier_len + cipher_name_len + 3); - (*algified_name) = kmalloc(algified_name_len, GFP_KERNEL); - if (!(*algified_name)) { - rc = -ENOMEM; - goto out; - } - snprintf((*algified_name), algified_name_len, "%s(%s)", - chaining_modifier, cipher_name); - rc = 0; -out: - return rc; + return 0; } /**