Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1348182lqp; Mon, 15 Apr 2024 04:01:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWhiKvOI7plxRf7SrwqEVYaouvMcWKazhki58taTwBUzpnKB2HSiynvx0g/eEilNDiVWtoh75sJMuqI6fk1+tGwoSTm+lV0M6W38Utu/Q== X-Google-Smtp-Source: AGHT+IGV3cDj5hqveRKHqoJtL4+D3oGVuxdU1zfs46ao1yC3OumBVpT6QDEU4w5NYXdOO192Wa5z X-Received: by 2002:a05:6a21:1f09:b0:1a9:3ac0:f1f1 with SMTP id ry9-20020a056a211f0900b001a93ac0f1f1mr7009051pzb.34.1713178903963; Mon, 15 Apr 2024 04:01:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713178903; cv=pass; d=google.com; s=arc-20160816; b=C5C0wG9z+qecwpJWot3HeZCttjNO3X/2hDzmFhuuQGPNChOAcaySLNOk8ylzdvtEkw lqE5LZgfzunXpSrCuhUeQinsarC6PUIWPQt5XXDVlcEl5hQyHOC9EdSz5YpyuzZ3RhOu 5yFV3eNBjh7+fzNNZiSpqi3ei1YAdK0SqnvCpwyCLUSMWrUykT0H29Tc9sI05br9bzqk ddfPq4i6Lxoex4R+jDXR/vJVvt/rzkQc2G/qCelqMzDF0bJmPW3k7yQnFgV5O77Ox0zj KIhDoT11bo2/lFWJiOLzLMTx4T60zP+P0N5IHX8GBPKl98UqGhrglivHzhGTTz1wP19t 4mEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=53+0SzuiMs1RjmWHMyjva+aVeSf9FjSdYiykUdQ8VVY=; fh=R8zJjlAF5b/cvvBPy4Jt1KlOwD9ZffanwgbCRgW9QXE=; b=CGQifGwSva7KzQz/rxJSOY6JVWYUwrQjvuzEp9wNOvOvRqfw+YCfEvdAXyVJvrL8A2 h8mdPFLztmsP76/oQE1jXs+KwIVvFr+pGAZwLXgn8IV8QwKoSnnmHD5YHLXvDTQlj1b/ ddLxY+70xiflXsJRVCxX3ZDZDMxVq0wGhVlBqJqcQmtY4pPXQiCU8RSQuRxwBT73LfOu rH4JslWHIcfIqKGQcqt4beQJv26ggxbaD3ivLGTzNjh+5w9JrIYmJz+ZeMKdk6OLGozv uNz8FVSD5nocYvcQPWWz9ENcm0wDvwqA163tTcUKsv1A5oi6LavBqlRPvPo+8powFPZM BtWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-144948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t13-20020aa78f8d000000b006ecef1eec86si7631874pfs.239.2024.04.15.04.01.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 04:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-144948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 551FDB25086 for ; Mon, 15 Apr 2024 10:54:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A83B35EE76; Mon, 15 Apr 2024 10:54:13 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03D7E5FB85; Mon, 15 Apr 2024 10:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713178453; cv=none; b=tZdsZ25HY8zosQqaqD1VGLaMfH62h6z/ehULadv5N8FE4wxFPk2RMy3reG3hASygC9fHpzsJTHnHGuzIwzYZbQXCBJlRN5WIm61wqYIegNGfKmB6zo2MZBW9EfkA0QMZ+6QzqqSnFk0UDammVs6BtjX1Y83Lc1pS4zQJ9ORWpOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713178453; c=relaxed/simple; bh=u+i3N7jlLOD5vzYSaTLemnLG3D1CGWWLFttmuOAvoi0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ROuIshM/yP/g1x5kiWNsOXbqC5L38d2bjoFPFQuxeNYnJd6lYzhGEhRTnUOwVoqg5Lh/NUdsktRcInX+Lyfy5ZRqZkqO7Cqglts19S+erl1DXmPnQoDarmLB1VaaqcRfTm0JJPz3HV+mswFw+ku896PUfGqrHfg5QOEvoQAwWhU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VJ3qv4VK0zwSHQ; Mon, 15 Apr 2024 18:51:07 +0800 (CST) Received: from kwepemi500024.china.huawei.com (unknown [7.221.188.100]) by mail.maildlp.com (Postfix) with ESMTPS id 8BC9E1402DE; Mon, 15 Apr 2024 18:54:08 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 15 Apr 2024 18:54:07 +0800 From: Zeng Heng To: CC: , , , , , Subject: [PATCH] pinctrl: devicetree: fix refcount leak in pinctrl_dt_to_map() Date: Mon, 15 Apr 2024 18:53:28 +0800 Message-ID: <20240415105328.3651441-1-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500024.china.huawei.com (7.221.188.100) If we fail to allocate propname buffer, we need to drop the reference count we just took. Because the pinctrl_dt_free_maps() includes the droping operation, here we call it directly. Fixes: 91d5c5060ee2 ("pinctrl: devicetree: fix null pointer dereferencing in pinctrl_dt_to_map") Suggested-by: Dan Carpenter Signed-off-by: Zeng Heng --- drivers/pinctrl/devicetree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c index df1efc2e5202..6a94ecd6a8de 100644 --- a/drivers/pinctrl/devicetree.c +++ b/drivers/pinctrl/devicetree.c @@ -220,14 +220,16 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev) for (state = 0; ; state++) { /* Retrieve the pinctrl-* property */ propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state); - if (!propname) - return -ENOMEM; + if (!propname) { + ret = -ENOMEM; + goto err; + } prop = of_find_property(np, propname, &size); kfree(propname); if (!prop) { if (state == 0) { - of_node_put(np); - return -ENODEV; + ret = -ENODEV; + goto err; } break; } -- 2.25.1