Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5761205rwb; Tue, 22 Nov 2022 04:44:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4808P5lvuWH03uuW/hw1aK/W16IA+c8BC2ktuSifHRUhtwg4Qu5PMBfl0xCopopQ3U8rAW X-Received: by 2002:a17:902:b682:b0:188:f8bd:9589 with SMTP id c2-20020a170902b68200b00188f8bd9589mr7273793pls.91.1669121056260; Tue, 22 Nov 2022 04:44:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669121056; cv=none; d=google.com; s=arc-20160816; b=o4rBAVXlOYbraZWuPtU9fc3cqo2MpNDTuQfucnLMmDwU9E+oyU3lhlb1xwpCUr1Z2k AgNwknAP6pwxrO5N2N1moU4XpGpVqsClUVnrcIhhKQfHtyaqbRDpHR7GBPrOrYkxFB57 EkHHHQrdeSlUY53yc5vAEYAAxJnwEkgWlyJxI+mSLs4hHOwJZhxwF0qk3Cxw3KcoHLT6 HiBCUGCKV4Wu8UnliciGUYE0kauDlDT4S953R4LKY9z1hn6vjxgy62Fk9FtrO/oVR9EG yMZwEd6BV0GjusZljtbsH2yu46ZInKBFZywrS3HR9E2tNXTjXb6YbdnrHrfnK6wWL+Ad CwHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=Xsrx39XMk+DwNsD6IZVJYubefOV/SuVYtbRlfdlQW/4=; b=1C06y/SlFOzf7DCBgBvyzCupKaF+J6ifJrKrUX9yoRQjtjoWOsDX853zKy0AUxqvT1 iat9z035eMoerH2u0gPHcsyoAmeigOiaTZn6TPUQA6DccCvZchXWlpWspjBcWDF7GnHs DvaBuBQVa8Kkaatg1yZXVbN8lA2ZcXQyiRAkAZjJSvEr8MWmbX6EndmN3XWjRLDMTsG8 z+hxErM3ffiAHrcnb7Ak2WYnpDbGKH8Gho00lY/kAcR9YXBEHH3wfHhyPZXT1kpG7J+U 6wVcYz2f++nnkPG3dIFrC1SFjOzSlAoUmCevMQlk3ag+z6zT1h3bBJhUEbNA/Zd0KDM3 VqoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20190130-41we5z8j header.b=SDOuKnd6; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a170902b20200b001786b70f913si12708184plr.164.2022.11.22.04.44.03; Tue, 22 Nov 2022 04:44:16 -0800 (PST) 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=@mev.co.uk header.s=20190130-41we5z8j header.b=SDOuKnd6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233645AbiKVMSV (ORCPT + 90 others); Tue, 22 Nov 2022 07:18:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233548AbiKVMSS (ORCPT ); Tue, 22 Nov 2022 07:18:18 -0500 Received: from smtp65.iad3b.emailsrvr.com (smtp65.iad3b.emailsrvr.com [146.20.161.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CA444AF08 for ; Tue, 22 Nov 2022 04:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20190130-41we5z8j; t=1669119493; bh=/bHcV3q6ab13X+W7DfnSMXsXfRWiQ1Kg1aBJ9B4LJuM=; h=Date:Subject:To:From:From; b=SDOuKnd6rGqpu9VmMfaIpMyXR+wVJHB6yi2KqNMMIWGGZdE3S3GXKGdg4GJ8IBV8t 6qg2tFPZfq6WpeSbxG9XwRV+KUFtxmrL2y+7xrlhhDlXqjpYqb4jn4PnB8TJfQLhRr d23mEqzpwtI7tF6KeuE9ivjadDZzDr01lDjzs1A4= X-Auth-ID: abbotti@mev.co.uk Received: by smtp9.relay.iad3b.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id BA7F7200AC; Tue, 22 Nov 2022 07:18:12 -0500 (EST) Message-ID: <94fee07a-0ac4-fba7-23cb-0a9da42e25d0@mev.co.uk> Date: Tue, 22 Nov 2022 12:18:12 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] comedi: drivers: pcl730: Fix potential memory leak in pcl730_attach() Content-Language: en-GB To: Shang XiaoJing , hsweeten@visionengravers.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org References: <20221122120428.25069-1-shangxiaojing@huawei.com> From: Ian Abbott Organization: MEV Ltd. In-Reply-To: <20221122120428.25069-1-shangxiaojing@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Classification-ID: feb35fc1-cd6e-464e-a8b1-8c7877bce722-1-1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 22/11/2022 12:04, Shang XiaoJing wrote: > pcl730_attach() calls comedi_request_region() and won't release the > resource allocated by alloc_resource() when pcl730_attach() failed latter. > Add release_region() to prevent memory leak. > > Fixes: 6f9aa29b47f6 ("staging: comedi: pcl730: use comedi_request_region()") > Signed-off-by: Shang XiaoJing > --- > drivers/comedi/drivers/pcl730.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/comedi/drivers/pcl730.c b/drivers/comedi/drivers/pcl730.c > index d2733cd5383d..c463de8a14e1 100644 > --- a/drivers/comedi/drivers/pcl730.c > +++ b/drivers/comedi/drivers/pcl730.c > @@ -274,8 +274,14 @@ static int pcl730_attach(struct comedi_device *dev, > return ret; > > ret = comedi_alloc_subdevices(dev, board->n_subdevs); > - if (ret) > + if (ret) { > + if (dev->iobase && dev->iolen) { > + release_region(dev->iobase, dev->iolen); > + dev->iobase = 0; > + dev->iolen = 0; > + } > return ret; > + } > > subdev = 0; > This is not needed. If the 'attach' handler pcl730_attach() returns an error, the 'detach' handler comedi_legacy_detach() will be called to clean up the allocated resources. All the comedi drivers work that way. (A lot of them have an 'auto_attach' handler instead of an 'attach' handler, but the error handling is basically the same.) -- -=( Ian Abbott || MEV Ltd. is a company )=- -=( registered in England & Wales. Regd. number: 02862268. )=- -=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=- -=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-