Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5812571rwb; Tue, 22 Nov 2022 05:21:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf71Mva704BpfACNB5q9NPS99zG9kEezTvdg/9NohiH5QTYIge9E4MBPvHLuoLQ6lHMrUVLb X-Received: by 2002:a17:906:6782:b0:7ad:7d50:dec2 with SMTP id q2-20020a170906678200b007ad7d50dec2mr20878595ejp.37.1669123286824; Tue, 22 Nov 2022 05:21:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669123286; cv=none; d=google.com; s=arc-20160816; b=LDJXITzwpeOa4MeMbntvYEGFwEUACn9gnbT3UX3Qyvy1DgIJJuMNjiovh28MUFoNNx CwS08UJbKqChIgHXWHjM5XADcqk+EIv6L65ufrA/tkg2ygbykXoc++R5hjn0FiY/NyvK MkB6Nr9qJ/To7lIuBA128Ulj/jWgGesI5sMwv4svVMxrhy9BkuH+8SnYo1yL24xX8crq /6bGo8vTSJYR8bMK6rFgB98iJIM6PJx3U+DRoKtVf712FWx7ZtRqLkeY2GHGKQuCjp1m 7ZE7+elc/iTQnNpt2pWb108hMIwIza2uJpL+aUXphlenWX+GSDIEHhn0GADcrKERK3US gVYg== 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:from :references:to:subject:user-agent:mime-version:date:message-id; bh=hTQbKDalwGeqPphgGCBMdqGG/2QRTKD+2Y6goIhsmzU=; b=vg06ISFCP3NbSF6CmruCWWY2nl9VUQkxbxHXfZsCmMuEoQ4m+M1uftrfA47l9fzy/Y qYu3V+lyB0bBAospxNlBzwWpYNQYGHHo4DehIgVf25BpE9ZsOe+CAHe8OlAwZz5oNW+F nghYxJyLt1CxsK+ylE/qiDXsRDus4Y5MwM2BIRkt24GLIl5TbdOuedA0OdxHhy5dJufz K3LzW2aBbJW5bvL0hDT9bpApLd4KC5GRTFVKRvzgQBZem3KS/leaB0Ry4mmHO0BSy6wz iGzu9NrcSShDRzhKx8HZr2mKkEu152/YjUiurLJhEQiks+FP0RMCJIika7EfGgfwcyhT du1g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ov8-20020a170906fc0800b0078d3a35e181si9527637ejb.871.2022.11.22.05.20.39; Tue, 22 Nov 2022 05:21:26 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233726AbiKVMYS (ORCPT + 90 others); Tue, 22 Nov 2022 07:24:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233689AbiKVMYP (ORCPT ); Tue, 22 Nov 2022 07:24:15 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE4E127FF9 for ; Tue, 22 Nov 2022 04:24:12 -0800 (PST) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NGk263YlxzRpQq; Tue, 22 Nov 2022 20:23:42 +0800 (CST) Received: from [10.174.176.230] (10.174.176.230) by kwepemi500016.china.huawei.com (7.221.188.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 20:24:10 +0800 Message-ID: <2f4dc5e8-1b2c-e071-a363-d3f509cc4ccc@huawei.com> Date: Tue, 22 Nov 2022 20:24:09 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: [PATCH] comedi: drivers: pcl730: Fix potential memory leak in pcl730_attach() To: Ian Abbott , , , References: <20221122120428.25069-1-shangxiaojing@huawei.com> <94fee07a-0ac4-fba7-23cb-0a9da42e25d0@mev.co.uk> From: shangxiaojing In-Reply-To: <94fee07a-0ac4-fba7-23cb-0a9da42e25d0@mev.co.uk> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.176.230] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500016.china.huawei.com (7.221.188.220) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,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 2022/11/22 20:18, Ian Abbott wrote: > 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.) > ok, thanks for the advice! Thanks, -- Shang XiaoJing