From patchwork Tue Nov 22 12:04:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shang XiaoJing X-Patchwork-Id: 24330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2163622wrr; Tue, 22 Nov 2022 04:14:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf64FthoqcEHChDGr3XICulzO7XTRTzGegJdSYfsl+oOiTaIUXprjSC7l3n3uqlXx7CdfI5I X-Received: by 2002:a63:4545:0:b0:460:936b:ded7 with SMTP id u5-20020a634545000000b00460936bded7mr3189072pgk.149.1669119276101; Tue, 22 Nov 2022 04:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669119276; cv=none; d=google.com; s=arc-20160816; b=OODyB5gn4HoCXJxcMisxJnnF15lY9zkpVu31DaVux0TZqzdAsU8/7iAaSGbOmiWUUi 78euKnHwFx81odojXXS7aTpanNVb+tAe3+qbNg1hqaI4wk8kr4wtQy5S2lDGqU8MssV7 ZGmpgaYsiHiqaMtgiqYPM43on4aeFHNVV6/ytAiWrxUkyn12XxLl2o4q9OcTdpgQf7ev HIJfSqa502T/NJSqlOckcon+a5l8jS592OJcvCtmTcaBn7LDtwFWmzw9RpMlo3yq4Kee 5KYrbVv2mjBeiryFeKPY/waF0aZaF4lN+Uc5AatOC0miOfGdTRlUMcb/KayefC6DO61B 0l2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=LGFoYHzpoorZS6wRs5K4N5ccJO2koAs+bPY70hM1C7A=; b=QeQYtam0ql6j7C+7vwEn0h9njQlGfHD5K4qnuvOOivyQXAbnZcc2oV4iEb55bKVTOE UGYHroRUf20NdVaYzAb9NCZMaHHtO4lZ0lYdU5cNsYV1N6At2WNcoGkwAS9qzVVr1Uk2 Mn4g3NEGH1qRZ3YyHgWeJD0th+FIOIothMj8y/yePmQhIBdZrvdFJYcsg2srLIJMG1hu rOH/DCk56MJ4Fm+KOhET3xRkotEMLTdoTa4x/T+QOpBeWtMMdRMiuRjA+BidDcA6Nun7 EgsWqWzNt614BblKFuGJIwIp0KYS2YEOxxj2D0r9ssYw1U4fSPq1CaxRJSWXaBwtlpLN iPcQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q15-20020a056a00084f00b005614fb190e4si15313140pfk.193.2022.11.22.04.14.22; Tue, 22 Nov 2022 04:14:36 -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 S232825AbiKVMGQ (ORCPT + 99 others); Tue, 22 Nov 2022 07:06:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232588AbiKVMGO (ORCPT ); Tue, 22 Nov 2022 07:06:14 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B052FFE1 for ; Tue, 22 Nov 2022 04:06:13 -0800 (PST) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NGjdK0qYLzmVvB; Tue, 22 Nov 2022 20:05:41 +0800 (CST) Received: from huawei.com (10.175.100.227) 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:06:10 +0800 From: Shang XiaoJing To: , , , CC: Subject: [PATCH] comedi: drivers: pcl730: Fix potential memory leak in pcl730_attach() Date: Tue, 22 Nov 2022 20:04:28 +0800 Message-ID: <20221122120428.25069-1-shangxiaojing@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.175.100.227] 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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750198414227941130?= X-GMAIL-MSGID: =?utf-8?q?1750198414227941130?= 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;