From patchwork Mon Jun 18 17:30:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 139040 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4214336lji; Mon, 18 Jun 2018 10:30:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLEASZy+IUqX22zLd26gTI3UUjHYq9bhJrYi7g3hY0EzekgtfbZamrpNxjSr9+ky/W4Ebe1 X-Received: by 2002:a17:902:4424:: with SMTP id k33-v6mr15049669pld.242.1529343056583; Mon, 18 Jun 2018 10:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529343056; cv=none; d=google.com; s=arc-20160816; b=k+BRC6/xP2FjuNOtwKV1hJ4TnwyBZAWiLGJvu2z9YzR2Hb5wa20h5LWT+5T2ZR1USF LksERgEyT2DmPjqSVFLCBO500UQqpyBO6o73Ey7ZoiMBq3BKYCEI/yoXj9+8cs0bStXC ZdpXxeII7iKgQz/TqcTpc7gf85paVlMboKpgzy8eySlHWOJMjm+xOOXOLQQry3LYUBXT wy73y5q/wO75fn5pWGg17SyukkKWR/jioePsILxASDZBE6eSeMWPmX5DVPoKVK0yc/mw YHNy1BgoJddMLSzWfc3mrN27SQFxfXPnQET9NXdyaRFtsbpiH0ckDHPYLJLSJ1kTP5Ir nI3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=BW0mPsFy5Hjtsf+iYw1mJMnHI+/88ZFKWRxjkWK7qf0=; b=D8Ni4juBcz/DkHtCyI3HwiZVFL5n36myTzp4h5y2QAQV9FkhHwnE4zPHYbb+scPF/l smZJ7lt0Gll2A7PbonLb9u4KrXvrL7poq1jHot1tuZDET6734tXy63kHQnBdzvSKGymu R2a5eyB+wwk9PcP3VFXya7poq78qr1ey6TjdBF3QRfsoJMdUGeiWC9+qeL9Srb6dI/60 DyUo1YAxa4X3OsjLJwas3S1f3jKXGU80QnkIcpzKF7ijBfC3E7vjdXnXzsiz7dfIE/m4 M18PFY5iJGr0fX1VwgB3zAFfdzDmXO0oRZ0KGJx1KmoRwFKi2X/y48h6e5RlwBohrXO2 wdbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Gsz6F+/q"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68-v6si646652pfo.229.2018.06.18.10.30.56; Mon, 18 Jun 2018 10:30:56 -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; dkim=pass header.i=@linaro.org header.s=google header.b="Gsz6F+/q"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935472AbeFRRay (ORCPT + 30 others); Mon, 18 Jun 2018 13:30:54 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:50450 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755076AbeFRRax (ORCPT ); Mon, 18 Jun 2018 13:30:53 -0400 Received: by mail-wm0-f65.google.com with SMTP id e16-v6so15428407wmd.0 for ; Mon, 18 Jun 2018 10:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BW0mPsFy5Hjtsf+iYw1mJMnHI+/88ZFKWRxjkWK7qf0=; b=Gsz6F+/q3I+tlhZ3oIqGv6O8mg97MO29LXg1YpdYY86SQcJSCF6mOBGGWPPPaI8JH8 y13xC8cEgr05WqoNCVfeU2p4ATTVFzDwvoVwvoLi++CIqq2hzK8hnEcwzTy41EJIRXj5 oKt4p2k7Uf8ynuG+ek7sNFIxkena1PC0VG4MU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BW0mPsFy5Hjtsf+iYw1mJMnHI+/88ZFKWRxjkWK7qf0=; b=GajuG1CHn+0h+d8RC/cmHFNAn7ZhNwGHWqebMo8aUNcNetdSCQkJLRvXcguJtW1svw Bnk0WhIuZSk2Uks/PBNpyDcwYuCFNoNYM/2Fsy+HkMKv4jFRMth5F1HIV496u+YMb7uB jxhYFV2Dex6qXW1CH/gllwOGKVIzkioK7K8qrXu0MqzUF+s1cuE6e4n1c0VSzoQxik6+ ohiVVctwUQRyBPu/vHCdqF5tRMIq+BVJ0P14j8CC0zdZUr0BQq+rAMsYRVplwqoWZNzZ VwwRr0KpCeyIyEm5GvAb7Cj01wVFw5DGOKiuqV1akZSK20HgvsW9shT7Nz2jhzjhKStV Jf1A== X-Gm-Message-State: APt69E1Py79TwWO6QFdDz/P1+yoLmG+0EIiiUHFywEq5AFsHoyqampxM /HpcHS2JClU8bs782PQTDlvuVo92r3w= X-Received: by 2002:a1c:c241:: with SMTP id s62-v6mr4620240wmf.146.1529343052019; Mon, 18 Jun 2018 10:30:52 -0700 (PDT) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id t11-v6sm12846787wrp.94.2018.06.18.10.30.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jun 2018 10:30:51 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, srinivas.kandagatla@linaro.org, Douglas Anderson Subject: [PATCH] nvmem: Don't let a NULL cell_id for nvmem_cell_get() crash us Date: Mon, 18 Jun 2018 18:30:43 +0100 Message-Id: <20180618173043.8880-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.16.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas Anderson In commit ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips") you can see a call like: devm_nvmem_cell_get(dev, NULL); Note that the cell ID passed to the function is NULL. This is because the qcom-qusb2 driver is expected to work only on systems where the PHY node is hooked up via device-tree and is nameless. This works OK for the most part. The first thing nvmem_cell_get() does is to call of_nvmem_cell_get() and there it's documented that a NULL name is fine. The problem happens when the call to of_nvmem_cell_get() returns -EINVAL. In such a case we'll fall back to nvmem_cell_get_from_list() and eventually might (if nvmem_cells isn't an empty list) crash with something that looks like: strcmp nvmem_find_cell __nvmem_device_get nvmem_cell_get_from_list nvmem_cell_get devm_nvmem_cell_get qusb2_phy_probe There are several different ways we could fix this problem: One could argue that perhaps the qcom-qusb2 driver should be changed to use of_nvmem_cell_get() which is allowed to have a NULL name. In that case, we'd need to add a patche to introduce devm_of_nvmem_cell_get() since the qcom-qusb2 driver is using devm managed resources. One could also argue that perhaps we could just add a name to qcom-qusb2. That would be OK but I believe it effectively changes the device tree bindings, so maybe it's a no-go. In this patch I have chosen to fix the problem by simply not crashing when a NULL cell_id is passed to nvmem_cell_get(). NOTE: that for the qcom-qusb2 driver the "nvmem-cells" property is defined to be optional and thus it's expected to be a common case that we would hit this crash and this is more than just a theoretical fix. Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips") Signed-off-by: Douglas Anderson Signed-off-by: Srinivas Kandagatla --- Hi Greg, Can you please pick this one for next possible rc. thanks, srini drivers/nvmem/core.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.16.2 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b5b0cdc21d01..514d1dfc5630 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -936,6 +936,10 @@ struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *cell_id) return cell; } + /* NULL cell_id only allowed for device tree; invalid otherwise */ + if (!cell_id) + return ERR_PTR(-EINVAL); + return nvmem_cell_get_from_list(cell_id); } EXPORT_SYMBOL_GPL(nvmem_cell_get);