Received: by 10.213.65.68 with SMTP id h4csp76592imn; Mon, 12 Mar 2018 07:14:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELt/sCdhj23rZQCsqFAmLAv16PAmKk/Nv2g4G3rTxcZAK1rF16PaLptBxqTUXK6bV2lf/xda X-Received: by 10.101.101.5 with SMTP id x5mr6724420pgv.195.1520864071247; Mon, 12 Mar 2018 07:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520864071; cv=none; d=google.com; s=arc-20160816; b=NOovZl464BbLc3vRyr7EHxOdm0cFFw/8XwTp2R7qvO2UKiwV8C0X5k198NQG5J6tBJ xFfobN9wmatu8yLY7PzQWjwMdrDiH8LY3RoHJ5eHBnDTQyzqkj3o7ukk348W3Zma5X58 7lCP+kUdOMKBQyimcUSnn6gpvjXvATMmQGWZQDqZSYJEPEtEPvA4nsr6tAfnIOdd9FGL TzrEZWFB++I/pVD/pvEU+8jgBPlAWQk6Mt0sO9mzxIjP1+ApVLe5iShDju1r2r2lBpP1 7KGYGLy1iWCMpEUvkkjORDFB3tlN3dHxH3FcMU6XQw68A129T9DFC+fMj84v2mllf8UY dYsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=nS2hI1dmMR00AMf8bETcmagps89WIZdfRQlBk91SKfQ=; b=ONlAVJHDcbotrU89IDQwtakPFd6LmeRDSmspzEtHybhrJxhzqGq4/+pm1qM/HDzpZU rlVsXvnFakwpZiVDjOGxYrL8XYeTfAElCNAgqQp4yW39RxJSiYfhwBuWcqgZMA2l+w9F l2zJb3WHPvGOXghwpwsRrRRuv1XxhBKQ3akVUgnMNYEgV1zv8Zbk+Iyr5LUUapFlCHTo tMcIuBn48nM/D87iY+MY0e64kkC8oCuEh6EEczUVAY3Cw3e62lcxYWAkxvgnMhHRgYI/ 5dFPWwbN7K6jkNeZNu7GKxcgZUCPt7ObFuwIFqXGFN9gZLydCnGoHxrpODMOXQaQZb8/ Rm6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si3410678pgq.665.2018.03.12.07.14.16; Mon, 12 Mar 2018 07:14:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932481AbeCLOMf (ORCPT + 99 others); Mon, 12 Mar 2018 10:12:35 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:47767 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbeCLOMb (ORCPT ); Mon, 12 Mar 2018 10:12:31 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 400KgX2fVGz9ttFP; Mon, 12 Mar 2018 15:12:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id Yy4wH_JVYcxu; Mon, 12 Mar 2018 15:12:24 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 400KgX1lKtz9ttBV; Mon, 12 Mar 2018 15:12:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 17F068B84A; Mon, 12 Mar 2018 15:12:30 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id kZoH4eVjvsFU; Mon, 12 Mar 2018 15:12:30 +0100 (CET) Received: from PO15451 (po15451.idsi0.si.c-s.fr [172.25.231.30]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CBBA88B82B; Mon, 12 Mar 2018 15:12:29 +0100 (CET) Subject: Re: [PATCH 1/2] crypto: talitos: Use common error handling code in talitos_edesc_alloc() To: SF Markus Elfring , linux-crypto@vger.kernel.org, "David S. Miller" , Herbert Xu Cc: LKML , kernel-janitors@vger.kernel.org References: <330e4ffc-64dc-5474-4c84-916561cf0783@users.sourceforge.net> From: Christophe LEROY Message-ID: <09aa55b5-1535-b5ce-0682-3c51fdf18387@c-s.fr> Date: Mon, 12 Mar 2018 15:12:29 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <330e4ffc-64dc-5474-4c84-916561cf0783@users.sourceforge.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 12/03/2018 à 14:31, SF Markus Elfring a écrit : > From: Markus Elfring > Date: Mon, 12 Mar 2018 14:08:55 +0100 > > Add jump targets so that an error message and the setting of a specific > error code is stored only once at the end of this function. > > Signed-off-by: Markus Elfring > --- > drivers/crypto/talitos.c | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) > > diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c > index 6882fa2f8bad..a2271322db34 100644 > --- a/drivers/crypto/talitos.c > +++ b/drivers/crypto/talitos.c > @@ -1352,29 +1352,24 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, > if (!dst || dst == src) { > src_len = assoclen + cryptlen + authsize; > src_nents = sg_nents_for_len(src, src_len); > - if (src_nents < 0) { > - dev_err(dev, "Invalid number of src SG.\n"); I don't think this is a good idea to move this dev_err(), just because the text is identical twice. The code is more clear when the text of the error is at the error. Also, as this text is for the case where SRC SG is identical to DST SG, the text could instead be "Invalid number of SG" > - err = ERR_PTR(-EINVAL); > - goto error_sg; > - } > + if (src_nents < 0) > + goto report_failure; > + > src_nents = (src_nents == 1) ? 0 : src_nents; > dst_nents = dst ? src_nents : 0; > dst_len = 0; > } else { /* dst && dst != src*/ > src_len = assoclen + cryptlen + (encrypt ? 0 : authsize); > src_nents = sg_nents_for_len(src, src_len); > - if (src_nents < 0) { > - dev_err(dev, "Invalid number of src SG.\n"); > - err = ERR_PTR(-EINVAL); > - goto error_sg; > - } > + if (src_nents < 0) > + goto report_failure; > + > src_nents = (src_nents == 1) ? 0 : src_nents; > dst_len = assoclen + cryptlen + (encrypt ? authsize : 0); > dst_nents = sg_nents_for_len(dst, dst_len); > if (dst_nents < 0) { > dev_err(dev, "Invalid number of dst SG.\n"); To be consistant, this one should also go at the end if we want to be consistant. > - err = ERR_PTR(-EINVAL); > - goto error_sg; > + goto set_error_code; > } > dst_nents = (dst_nents == 1) ? 0 : dst_nents; > } > @@ -1424,6 +1419,11 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, > DMA_BIDIRECTIONAL); > } > return edesc; > + > +report_failure: > + dev_err(dev, "Invalid number of src SG.\n"); > +set_error_code: > + err = ERR_PTR(-EINVAL); > error_sg: > if (iv_dma) > dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE); > Another solution could be to move the dma_map_single() of iv_dma after the kmalloc(), in that case we could directly return from the other error cases instead of having the unmap iv_dma first. Christophe