Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp647821rdd; Tue, 9 Jan 2024 15:42:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRHbOylYKdSNnEqQ8MOWWfdnOac1xCOT9vPGSCWBJh3Ihr1tDV6L9eEi1mRS8xSZwBDG69 X-Received: by 2002:a05:6870:40ca:b0:203:bc5d:cf06 with SMTP id l10-20020a05687040ca00b00203bc5dcf06mr320242oal.72.1704843778650; Tue, 09 Jan 2024 15:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704843778; cv=none; d=google.com; s=arc-20160816; b=n6UklrnkjGA2bUYjKkh7ndazYHyhFRHhROM1sdOqJA+SYm4380fXIujvdSil8ezq12 WB3MM3vREH7zFqK/rRkwHEZjdpUhSruJcq7MSsEEUM4nkPO6u/SOqWmRgWxwo2PMZ+3L ptkpoMm8Aoi1H1JCJJ931FBbpheH+/Ka2G4zFmOVupF1q5QHXeWk0fW2RhTdjddxzCz4 iHhv/BnejTLS8tiFAPaDwOJ0j6ZrOgZzNDQMCAo4cHHZRh6R+OrzbouA+4r1QXgkqerh BLVBsxFpesUnRKtr8F25Vz/o/K1Kx9bjGnWDUEIIm7F6gTqBnbmN9mcy81cHUPaNOQxO Bpvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QIcPXVK1fYFTemMdjpiQGc+AOvdzW3M34c5/yKhDtd4=; fh=OLxS3XWGESJFIR1RnvI09pGJBSkPxXllHR5nwlh84is=; b=hu5H7BHjszH7pOIJbQS8VqOYrGvHfC3nM/Sega/a0LtFRIskMqJwUGCJ+YbAnn01W2 odN5uLj41CAUMHw68mx28vUsfWPBn8AVQs4CnEQuVu+OjXeqAc8aTKJoOQiTXgoNJSiw CebKUGvIpp7PlaRFe8zM8Jsg87QNn5Jaq7qc7Ut0H7Q1GcNq3sOt4SjBIWZqmyzOo8Gr DJ0gvyjwFJil0pJeZvUF9Y1V5v1RzTbxND84RXiqauYVfeQNgfXbonB4U/bBvQyqegeD fd8vXRlQJwj9pbsLv+UNC/8eLj4x8Ic2yn50LhnO9D97y64Zrl6x5yPUalo28J/ID1Jn UC2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="2X/fCjnp"; spf=pass (google.com: domain of linux-crypto+bounces-1315-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1315-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 5-20020a630005000000b005c65d0dd99fsi2353692pga.505.2024.01.09.15.42.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 15:42:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1315-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="2X/fCjnp"; spf=pass (google.com: domain of linux-crypto+bounces-1315-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1315-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 374AC2881FE for ; Tue, 9 Jan 2024 23:42:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DAC2364D0; Tue, 9 Jan 2024 23:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2X/fCjnp" X-Original-To: linux-crypto@vger.kernel.org Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D87D3F8CE for ; Tue, 9 Jan 2024 23:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-il1-f171.google.com with SMTP id e9e14a558f8ab-3606f507efeso17177045ab.3 for ; Tue, 09 Jan 2024 15:42:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704843764; x=1705448564; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QIcPXVK1fYFTemMdjpiQGc+AOvdzW3M34c5/yKhDtd4=; b=2X/fCjnpWleyUM89aPH0FD6rDIWGbLtUc2Mv15EvJVL5FPT0TO2L7pFdzX4GOsfqP4 rS18DElgEhNV9dk7NrG1b9UIO6YNdjbBNVjYcjCkpFHGhTqTnjfDzIUMBSq1AVUHRP0f yOb4rReEGaiwkslthXZHh9oquvcRXfjeTNELlvIK+JsvTLj0Nmh9AbLPY30wyHZjGfXH RbuDC/2hgS6QASD09oWCvr+nTnUu6tof+TYCbfEndNUAR79cj7rPD0zkS+g3if8uX55X +95LXNWegkGPPnzW6K9c+/dhd0EmumJtnhedDaR42BlVkOS7Vpj8vlRzq7u+TiyiV6xe +QDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704843764; x=1705448564; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QIcPXVK1fYFTemMdjpiQGc+AOvdzW3M34c5/yKhDtd4=; b=SFaKScMk0gldOu+aa2GjaknQhKNLnZrutiYndlvUSJnPNog8h06kxNJCo6tyE05SVo HrOL/uP5jXn/NNLM1hHx3rP4ogSQC9Wt6DEf9tlGEPdk6B/QjL+zpt2xMLnRWmL3OGfd wagVjeXCfJjNe+XOYc9rQHIo8z05VIfmxVdczkAq61izVbq9qMXZxM4UaBJuGZ9tmR6s +bxh4ldnWnDbJxVxGHogqpVY+QJcImPz1ThQXpzGJEUrUz/nuXQsMF+iBv5hi8ww90K+ 1i2JgPXVXojlsR/hODZgjs1n9qg0DWJZ2rzQSY1yGTG1Hk42UKRj3k1/qRTvK3xguu/p 6YOA== X-Gm-Message-State: AOJu0YyiMbWX6gWHjzxx5P9oJlJgFzNojd1VTh5pNwHDHg3ISR6GvCRa gd5Tmw+Kt54zh+Def44+RWZQzqIOpwkU X-Received: by 2002:a05:6e02:3208:b0:360:5cd9:a73e with SMTP id cd8-20020a056e02320800b003605cd9a73emr300419ilb.6.1704843764645; Tue, 09 Jan 2024 15:42:44 -0800 (PST) Received: from google.com (194.225.68.34.bc.googleusercontent.com. [34.68.225.194]) by smtp.gmail.com with ESMTPSA id em17-20020a0566384db100b0046ceccc798asm954664jab.6.2024.01.09.15.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 15:42:44 -0800 (PST) Date: Tue, 9 Jan 2024 23:42:41 +0000 From: Justin Stitt To: Markus Elfring Cc: kernel test robot , virtualization@lists.linux.dev, linux-crypto@vger.kernel.org, kernel-janitors@vger.kernel.org, "David S. Miller" , Gonglei , Herbert Xu , Jason Wang , "Michael S. Tsirkin" , Xuan Zhuo , llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev, netdev@vger.kernel.org, LKML , cocci@inria.fr Subject: Re: [PATCH v2] crypto: virtio - Less function calls in __virtio_crypto_akcipher_do_req() after error detection Message-ID: <20240109234241.4q3ueqdjz5o54oan@google.com> References: <2413f22f-f0c3-45e0-9f6b-a551bdf0f54c@web.de> <202312260852.0ge5O8IL-lkp@intel.com> <7bf9a4fa-1675-45a6-88dd-82549ae2c6e0@web.de> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7bf9a4fa-1675-45a6-88dd-82549ae2c6e0@web.de> Hi, On Tue, Dec 26, 2023 at 11:12:23AM +0100, Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 26 Dec 2023 11:00:20 +0100 > > The kfree() function was called in up to two cases by the > __virtio_crypto_akcipher_do_req() function during error handling > even if the passed variable contained a null pointer. > This issue was detected by using the Coccinelle software. If the script is short and simple would you mind, in the future, including it below the fold -- this may help others do similar work down the line -- Or you could also link to a git-managed version like what Kees has been doing with his __counted_by patches [1]. > > * Adjust jump targets. > > * Delete two initialisations which became unnecessary > with this refactoring. > > Signed-off-by: Markus Elfring > --- Nonetheless, Reviewed-by: Justin Stitt > > v2: > A typo was fixed for the delimiter of a label. > > drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c > index 2621ff8a9376..057da5bd8d30 100644 > --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c > +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c > @@ -224,11 +224,11 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request > struct virtio_crypto *vcrypto = ctx->vcrypto; > struct virtio_crypto_op_data_req *req_data = vc_req->req_data; > struct scatterlist *sgs[4], outhdr_sg, inhdr_sg, srcdata_sg, dstdata_sg; > - void *src_buf = NULL, *dst_buf = NULL; > + void *src_buf, *dst_buf = NULL; > unsigned int num_out = 0, num_in = 0; > int node = dev_to_node(&vcrypto->vdev->dev); > unsigned long flags; > - int ret = -ENOMEM; > + int ret; > bool verify = vc_akcipher_req->opcode == VIRTIO_CRYPTO_AKCIPHER_VERIFY; > unsigned int src_len = verify ? req->src_len + req->dst_len : req->src_len; > > @@ -239,7 +239,7 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request > /* src data */ > src_buf = kcalloc_node(src_len, 1, GFP_KERNEL, node); > if (!src_buf) > - goto err; > + return -ENOMEM; > > if (verify) { > /* for verify operation, both src and dst data work as OUT direction */ > @@ -254,7 +254,7 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request > /* dst data */ > dst_buf = kcalloc_node(req->dst_len, 1, GFP_KERNEL, node); > if (!dst_buf) > - goto err; > + goto free_src; > > sg_init_one(&dstdata_sg, dst_buf, req->dst_len); > sgs[num_out + num_in++] = &dstdata_sg; > @@ -277,9 +277,9 @@ static int __virtio_crypto_akcipher_do_req(struct virtio_crypto_akcipher_request > return 0; > > err: > - kfree(src_buf); > kfree(dst_buf); > - > +free_src: > + kfree(src_buf); > return -ENOMEM; > } > > -- > 2.43.0 > [1]: https://lore.kernel.org/all/20230922175023.work.239-kees@kernel.org/ Thanks Justin