From patchwork Fri Jun 14 10:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 166806 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1868872ilk; Fri, 14 Jun 2019 03:26:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9B9jpzcyr0gSyER62QjFS9Q7ARZaEFYucim/WrRSBO2vRr45IBeqkkHQySEo61x+c7uJ+ X-Received: by 2002:a63:6c4a:: with SMTP id h71mr32880859pgc.331.1560507983767; Fri, 14 Jun 2019 03:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560507983; cv=none; d=google.com; s=arc-20160816; b=vJmQLj98UyoZUOCK4atUrHtv/Td+GJP12nkF1/xb6bPcWVosaUXihsm9wwdYVQl5TC PIMuFulSuXBlM7UseR2Ldn17M6XGL0hJbTv4xusfpPachzSzJjwXcOtwXTeISflX5A24 JmLGc07LKO8mSJfODibO3qPRDo9fEUUgLD9kNXD/3nuXut7ori/HNVWBNfkd0fCc1EXZ LTHQLTrbSoZGEX/9xGfj7LtexWnfs29RVtEs/XE4blg42ZE0bf6LQQTH9yWsLnKi+eU+ s0Qo+coxz8QfsV3iL1JZTCbSMqDpzni67VAWQqd0mI/P1PCIMuID6VKhY9I3KqEeRMUM +uVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=ZHKx5MOjQIW9zZO/yYvPP4VbDN+ChMTughF/NRzvKmA=; b=yHzUkqSJY9xQnXk1DejAOsVnDmrqRyb3C4Q8Cw8x/AAL03AF1LirjvFTW6XZGX6JQ0 /wqzV81XjXVAKngyAFSmwe8DPqAkcrSbnFpxsBFmvgouiWv2waia/8exXzh6qroITtbm uFg4eUkk02WDdZ8CUfbugbKZiy7fOxU0gPHlCnhpTjeH3hDEMeRpky5jtoe02YXCFO+b DyldFcC6rnWlq3iLxAfSFTJ9jofRZKa2TmvucIFWK7I4Qa0B2yV8j9t/em8ux0Aia+PE 00wcEFuHtlQUc3eMZSeJMcaQ2pYf3fLLihp3uCijBdjrNv7wVICk6pjWEJ68hBJRi24Q lEAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si2026737pfc.55.2019.06.14.03.26.23; Fri, 14 Jun 2019 03:26:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727410AbfFNK0V (ORCPT + 15 others); Fri, 14 Jun 2019 06:26:21 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:18572 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726884AbfFNK0V (ORCPT ); Fri, 14 Jun 2019 06:26:21 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2E17F8C56086200B960B; Fri, 14 Jun 2019 18:26:17 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Fri, 14 Jun 2019 18:26:08 +0800 From: John Garry To: CC: , , , , , John Garry Subject: [PATCH v2] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range Date: Fri, 14 Jun 2019 18:24:53 +0800 Message-ID: <1560507893-42553-1-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If, after registering a logical PIO range, the driver probe later fails, the logical PIO range memory will be released automatically. This causes an issue, in that the logical PIO range is not unregistered (that is not supported) and the released range memory may be later referenced Allocate the logical PIO range with kzalloc() to avoid this potential issue. Fixes: adf38bb0b5956 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry --- Change to v1: - add comment, as advised by Joe Perches -- 2.17.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 19d7b6ff2f17..5f0130a693fe 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -599,7 +599,8 @@ static int hisi_lpc_probe(struct platform_device *pdev) if (IS_ERR(lpcdev->membase)) return PTR_ERR(lpcdev->membase); - range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL); + /* Logical PIO may reference 'range' memory even if the probe fails */ + range = kzalloc(sizeof(*range), GFP_KERNEL); if (!range) return -ENOMEM; @@ -610,6 +611,7 @@ static int hisi_lpc_probe(struct platform_device *pdev) ret = logic_pio_register_range(range); if (ret) { dev_err(dev, "register IO range failed (%d)!\n", ret); + kfree(range); return ret; } lpcdev->io_host = range;