Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2329821rwn; Fri, 16 Sep 2022 08:43:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ApZRHhF7C0kgxP2CASprB1ZFGdcHRvPK5syKrtLk5ZnvH9AHByVPcnxFGqv5oM6Msr3in X-Received: by 2002:a17:907:3f28:b0:77b:1ff5:410c with SMTP id hq40-20020a1709073f2800b0077b1ff5410cmr3984775ejc.117.1663343028057; Fri, 16 Sep 2022 08:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663343028; cv=none; d=google.com; s=arc-20160816; b=tiHScjGIbcor4OkFfHrvbvpfuif4/HFNq0ls5YkojNKvMFXv38TnMxRILBRVh8D0hl lSn4XblSlLXp7QcB9YfQ1I6TCD0jC5GYnOlRwe1TC+Fo215sSVHGjKoiaWUu2gfckvxN MkSKvD3GuisYpMV2dvx3QaXYhn4qvFQC4vSs1Rkx0PYLVqZHto9r9bSmUT7xMz2F+Lb6 cIuJt93wS8beeHwdruTyXue8vje8AVpLLiviCDOMVJghWfTwdrsuz0m4LhBpx+NZidlC uJeptnsN/geG4wWTeagQIHI7rzxYgmYSALKw5XhM+dYDDsWSwfiSqxHMD+pbvv69hi5z HuMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rcDieOXWzwDYad3Or3UKN2ift/v1pBenSYpheluB7r0=; b=zEmCmMPmhsFkCjhv702iWki2gPymyeZpEwWxc3arSTq4YpQ9L8z7I2jyqscTklFCPc 4Y0QPJC5GMnLzthDPG2zKprXsrUt94JxYae+cftj0vQpxg+sbKg887xjQX42cbnobVt5 bP7G0199MFGtcp08TAQwCCmfM2QiZDZa6DDqvdJH4EtwWmXIfy1Pq9W4ZIq9KdRErilI ARZ2ZjyainAN0GfRaANHN15pwycjF9/vMlwtstVdZkXMsMDiNbc+/kz7GBLRdbjoBgh9 v/wx6iUoNP+PMV4VmVLRpBx4DJE3Ehiocp72VQLs7BS5l8Jt1HEoEYPqhryzBBvcnu5P u5qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dZTwYhVK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020aa7dac1000000b00451db83b2d6si2247395eds.312.2022.09.16.08.43.22; Fri, 16 Sep 2022 08:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dZTwYhVK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbiIPPgs (ORCPT + 99 others); Fri, 16 Sep 2022 11:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbiIPPgq (ORCPT ); Fri, 16 Sep 2022 11:36:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C312F026 for ; Fri, 16 Sep 2022 08:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663342604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rcDieOXWzwDYad3Or3UKN2ift/v1pBenSYpheluB7r0=; b=dZTwYhVKP7/QEbTBOqJu/xJHwl998/L5uE0NVyPcWtR408SOE5wgpo2iClGQ141Df/iPCR Vn6Yc3Ce3LvKDAHLYI0XabzMhH3BRSdO4rUk8kzNdXrLSsNURc57dkJfP+Da3Y9O9UAxXZ WHaEqckE2R4k5hHbrzQgKNaN6QYdqhI= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-424-D9LIS7urO9a2bRx1RmfhwQ-1; Fri, 16 Sep 2022 11:36:43 -0400 X-MC-Unique: D9LIS7urO9a2bRx1RmfhwQ-1 Received: by mail-pj1-f70.google.com with SMTP id a24-20020a17090a8c1800b0020266349974so3236pjo.8 for ; Fri, 16 Sep 2022 08:36:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=rcDieOXWzwDYad3Or3UKN2ift/v1pBenSYpheluB7r0=; b=XKm3C5DOezcXYAwnuuYUfCEQfQ03ILtwHGr8vV0LaN8IHprTn81b5nx7HRX4SrtDjF T0VYz05mxlhiI5gdLUw7Zu4IGfF92ui57WeYfl7aYaG0EY57dO3QEyFaSVPgP8hFJqzi Gf3gkMupjEUdfM7xqh4XmRCgY7Sy//8pCo4zldeaK2Io1rbmt2hHhzeYbKdJpXVgYDNP Mab5qTqIX7XsFHsaN2yJg8MrqTmdj11Edwfc0nlgoqZPU/mnotUAfV2eqZaDV3m2U7Lc tw9sSEZ4gSEL2ujkNE8YFZ6LcFOR4pv3/b/17LWIG1O3s6tyoskYEhAkUECBFMric+hN /ggw== X-Gm-Message-State: ACrzQf3RZEn509XulZnzFsUA4uci9/5KZkhdbtbf1t+zL7U/1FRhq7RN FNhcp1SBcT5Ucn8Ny9hFDMUqA3/2Ds3zbsk1WtBB+Zw7fI5TyvzqJxCG6vcFGqZ0n7BGONI1KvQ 3+L5XF3ID/420mot+A7uU0qwL X-Received: by 2002:a17:903:11c4:b0:178:634b:1485 with SMTP id q4-20020a17090311c400b00178634b1485mr416685plh.142.1663342602567; Fri, 16 Sep 2022 08:36:42 -0700 (PDT) X-Received: by 2002:a17:903:11c4:b0:178:634b:1485 with SMTP id q4-20020a17090311c400b00178634b1485mr416662plh.142.1663342602257; Fri, 16 Sep 2022 08:36:42 -0700 (PDT) Received: from localhost (ip98-179-76-75.ph.ph.cox.net. [98.179.76.75]) by smtp.gmail.com with ESMTPSA id p20-20020a63e654000000b00434abd19eeasm13592258pgj.78.2022.09.16.08.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 08:36:41 -0700 (PDT) Date: Fri, 16 Sep 2022 08:36:40 -0700 From: Jerry Snitselaar To: Rafael Mendonca Cc: Fenghua Yu , Dave Jiang , Vinod Koul , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dmaengine: idxd: Fix memory leak in idxd_alloc() Message-ID: <20220916153640.qtb74i63upcncpuw@cantor> References: <20220914230815.700702-1-rafaelmendsr@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220914230815.700702-1-rafaelmendsr@gmail.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 On Wed, Sep 14, 2022 at 08:08:14PM -0300, Rafael Mendonca wrote: > If the IDA id allocation fails, then the allocated memory for the > idxd_device struct doesn't get freed before returning NULL, which leads to > a memleak. > > Fixes: 47c16ac27d4c ("dmaengine: idxd: fix idxd conf_dev 'struct device' lifetime") > Signed-off-by: Rafael Mendonca I think there needs to be a kfree(idxd) where it checks rc < 0 after the call to dev_set_name() as well, yes? Regards, Jerry > --- > drivers/dma/idxd/init.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c > index aa3478257ddb..fdc97519b8fb 100644 > --- a/drivers/dma/idxd/init.c > +++ b/drivers/dma/idxd/init.c > @@ -445,8 +445,10 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d > idxd->data = data; > idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type); > idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL); > - if (idxd->id < 0) > + if (idxd->id < 0) { > + kfree(idxd); > return NULL; > + } > > device_initialize(conf_dev); > conf_dev->parent = dev; > -- > 2.34.1 >