Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2383737rwn; Fri, 16 Sep 2022 09:27:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QCI3+v4dtDCloVYxbs7WdSACB4azJQjiV4HoDG47Q3zkqhCbi7kD5uEqxakNh88O5Stp0 X-Received: by 2002:a63:6ac2:0:b0:439:6693:5b2d with SMTP id f185-20020a636ac2000000b0043966935b2dmr5333452pgc.614.1663345645934; Fri, 16 Sep 2022 09:27:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663345645; cv=none; d=google.com; s=arc-20160816; b=WOrTFsj6xXAU/j2GZvaMOF4xUTS6cwYvUHFzXwIQ4ZFcHss6leO2CXF6FQXqITOPXV 9g/TaprmTDX9lKI3/waIh8y1AiPLJXiMMkJrKKjA89hVYkQRITIUc3G8LnMbM6EfWK/F LaINN86gW9faiRaU4FZtg0mFNQZCgms734CH8kNq4+JbUnpU55s6/0KpVJN/o6ewMawN DW2L9AH3Pbp53C9Q4VLm7dA/ksI0FtueZJpiFaZObsJcXlfFWHeDyf6xRPqqth4qtUTV HnsKwpdDsQivuLpjLeTFaPplU5e6a9Bh4qaqo1zKn7GgELBzksPpcqHyW1mtLL6hyRhg JScA== 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=N2Tln14Ocv6kONUatrxC5kt37vjmPJnPDfeEkInI1oc=; b=sqkk9IBKUfJVrfIV/2Mh7nAmwXUe9mwWQRP80JS+EpqpoTl+0LUxvYfBF31L9mvcMr sEZw+mFYOhNCFYa8cfvOhuaY1fQTBuoWzrv9fLrwHvxSKZFg3+jdVolIuto9z0bm8BAT iBn8B9dBEY9s1Xn6v5lySfq0f2meqyO1aiK1qcUemAraH3ETivGAlvNYA5aK2Om+Bytu DwXrjZKXmDGR6eJixC/tDo/c9OvQxdMHSs+tDBSb89rHwciJCOjvrH7HdC5ErfQmXt1h 5+hNdMzkfMmqjozpw82nBoMay2iun2vVYrML8gA5lrg5FF1rzXQvl/9YhUWgIH28pc+w PwxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hmHFRM3l; 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 e14-20020a6558ce000000b00429a132d2c8si13285104pgu.279.2022.09.16.09.27.12; Fri, 16 Sep 2022 09:27:25 -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=hmHFRM3l; 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 S229996AbiIPQRU (ORCPT + 99 others); Fri, 16 Sep 2022 12:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbiIPQRQ (ORCPT ); Fri, 16 Sep 2022 12:17:16 -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 0895BB6009 for ; Fri, 16 Sep 2022 09:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663345034; 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=N2Tln14Ocv6kONUatrxC5kt37vjmPJnPDfeEkInI1oc=; b=hmHFRM3lf13doqqRSlmaocqcc+TiG3Pm4QS48MDPHsO/jsNHNqA20obVFDA5DIUGJv/pSS w5k35YI4REpsM6G+rN874d36mUcXOzb5Z/s14LPoQ5iYrLLe0pZXC+j+GxjaS/2x7uNcPK 5de0+yFhVkPdHh230sgRZV6WZKrp978= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-322-lh4v1RnwPkuMPDgUjewTVQ-1; Fri, 16 Sep 2022 12:17:11 -0400 X-MC-Unique: lh4v1RnwPkuMPDgUjewTVQ-1 Received: by mail-pl1-f198.google.com with SMTP id n9-20020a170902d2c900b001782ad97c7aso11356331plc.8 for ; Fri, 16 Sep 2022 09:17:11 -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=N2Tln14Ocv6kONUatrxC5kt37vjmPJnPDfeEkInI1oc=; b=hMuE9twMraRJrISRxXoz968OevOKwQUeA+Mfmt1DDo3cgwluocGdjMTGT1agWW5K90 yeFWdKhFhWsTtsj3WUO39LM8X82sxMO5W2roOhXB3vHYPYgNH6aoLxpGScT5wrAip5vI TbywfAwTDFJvL2XR6pdu/nnvUL/1wMvjvjbd7ylBl4S0xFW3xZF3M+pYIqq8h1H7o/iR t8N3qkGdZvtF258zCtRfBPiPVLA/V82/gssAS9unI1BV5fkhCODIXdy+SZVa14PBD4ub YQ5EX3QHQluV+P+L3V2gdNhl9iAa0E7Etx+batr0nYqEsBy394hsoKTcdq6ocHUdVISJ XizQ== X-Gm-Message-State: ACrzQf1ut3CmbBYnkHYkSkohsIacEYJkjv9Sa/leAiHtm2WuGFUFmfqu 8IR2ZJvqkXbVlmaPXpscrhkbaH0kBPEpufk8p6kSmUo63j0sQ6vWUodAHYY6ExbdZ14bpug/OuE re/gsujQ8eFZjR/IC9SckcmId X-Received: by 2002:a17:902:7281:b0:178:388d:6f50 with SMTP id d1-20020a170902728100b00178388d6f50mr573447pll.127.1663345030623; Fri, 16 Sep 2022 09:17:10 -0700 (PDT) X-Received: by 2002:a17:902:7281:b0:178:388d:6f50 with SMTP id d1-20020a170902728100b00178388d6f50mr573424pll.127.1663345030380; Fri, 16 Sep 2022 09:17:10 -0700 (PDT) Received: from localhost (ip98-179-76-75.ph.ph.cox.net. [98.179.76.75]) by smtp.gmail.com with ESMTPSA id n1-20020a170902dc8100b0017508d2665dsm15100299pld.34.2022.09.16.09.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 09:17:10 -0700 (PDT) Date: Fri, 16 Sep 2022 09:17:09 -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: <20220916161709.p6srrszdp2qz2nmp@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=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 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 Reviewed-by: Jerry Snitselaar --- > 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 >