From patchwork Mon Dec 9 14:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899876 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FD9F1B042E for ; Mon, 9 Dec 2024 14:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754489; cv=none; b=irRk/spx2cN/PbqZvOi5KbeYk7Hqlf1rcB0s7hyncWQtoyGD9m3cu971N6TrXnB+l/tS2LSOgOgaOBVdiN8yzojbHBdre8xmrzKOSHP0fmiPPqtxMHKZX01rG07uGiYYijT7RgReE8B/EmItNFKVkDsu2Vu5czyiAJHxOenQeY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754489; c=relaxed/simple; bh=5RyUOr3QrW/O4bHLJREt2wIOvq1gkSc98ga8ZwgfQQM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NQAg0/ahZvjUEIfuHVvDXOMRVIpbF1OnAYP3ZY/jbJGE1tu8YXeYq++Lw01AI1BJp0sadF3Us/SJGgwoFTsv7SOFvIMPLrNynw/CgLn7QVs4pIy5AVnqiwOTYcef2QuASSxK7QRGAUGZqym8JosBOgCGi50yh3wBQTM2cAFlbC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=FkT8paB5; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FkT8paB5" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5d0bf4ec53fso697755a12.0 for ; Mon, 09 Dec 2024 06:28:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733754486; x=1734359286; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=p9z3NSZ89oX+1aCU37jpGmvgiUM/f0IkRVAkdzRLUng=; b=FkT8paB5WxO5gTDPCQtGFrDTQ+cw2TvnDhH8xn48oNpVTBo1Aunwpa3us079/fz/+c RFZM91oed/43wibHOHRa6AD/EYRVaBS1lzeswf6H4k43/W1ihLzFcspZLYLKxF+B9UX4 16u1+8FlQ7I+cbqJkzIwvv2RP4UJz2fDY+U5jaFgoGMS0e+nMWoGCzpQL4N3XbPK/Mze xq83xgo749O/p1jTfclKRaN9/2Iw3w/YJIxSW5uZW/8zyxK+o3iI+M+BXKC6fct5cDS2 AxAuvWAYMpXMIIGtUt1pniN6QZAla7h8Je/T6r1Gj1l41YXTe01quNu+f+ACObQ4JCkJ A1JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733754486; x=1734359286; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p9z3NSZ89oX+1aCU37jpGmvgiUM/f0IkRVAkdzRLUng=; b=EWWX5o/cmRnLSwgaFWVnwdre0Efaa1yC1Qju77TfVQC65UNR0UKOEJtQ/47zZytAmS eDsWBWnuowAcMRQ/CcLNs5nF9FOJxAZkS3k0Mx8tBQrLzVj+Fl1FrWndwEUQpgKJX3HX 7hxgFke01NPvuWe5K3DN39Xv01mvS8QEhUj9MVgGmA/voOgqUZxfvYMMbcqmoX0qNBiK /+7k93p+IAYvmmC+ombbGezG1NiuRok3XTbXR3/UFguE38nTesdaLVYMamKaHhruSgWu 3ZJuqIXt0AkxT6Ti8ZKNK8ycju6mDD8sIuNu0/uU+/9VCMprNDXc9hQQh7Vxa188nVAP QXSg== X-Gm-Message-State: AOJu0Yxzu56is09CaJTqvPOA8LJebcPcnhqfK/GMh+Enypc8Dh92AGs7 VeRcuC1KpgYDjvgz0nLRMu87G/2BMs2okiD6CPlkJ5XzZBv01gRVW6RGnBJn2CUt1l0rQJcqcaA H X-Gm-Gg: ASbGncs0IL1uuqzlY/EgPDhOa9ZcphKdio07TPgxwGD7GoV0XrUeZEK8h4kzgmIviXg AAT0gBQecCx/P4yNX42xawUuqRy6LALD/CvaKQgKUDLmnONisS1115LOLKBT8fvCBD/1SqjWJcy pLG9oAB0pYl3TBiYb1Jek1FQREsoYOzJCk+1CqE7rls32xL7JlmFS5/Nx92+Ef38iF99ulHRIsa pNbqOU5e1gmqNChsxQtirKpjUDkQ+AtVT/rDYkkCFPUNnAi4Q2QG4eXnZtDA/NEGA== X-Google-Smtp-Source: AGHT+IFIgdJJhInSnlqruzVbSu59rrKt4qd7stV49lWAt/BO7iNwOqoQYHrJ2/vjw5/XCTccLzxlYg== X-Received: by 2002:a05:6402:254b:b0:5d2:d72a:77f2 with SMTP id 4fb4d7f45d1cf-5d3be78e16dmr4723573a12.7.1733754485993; Mon, 09 Dec 2024 06:28:05 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm2887141a12.42.2024.12.09.06.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 06:28:05 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 15:27:54 +0100 Subject: [PATCH v2 1/6] firmware: qcom: scm: Fix missing read barrier in qcom_scm_is_available() Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-1-9061013c8d92@linaro.org> References: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> In-Reply-To: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Mukesh Ojha , Dmitry Baryshkov , Stephan Gerhold , Bartosz Golaszewski , Kuldeep Singh , Elliot Berman , Andrew Halaney , Avaneesh Kumar Dwivedi , Andy Gross Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2480; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=5RyUOr3QrW/O4bHLJREt2wIOvq1gkSc98ga8ZwgfQQM=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVv5t2ppbxpCTSeg/Ip6ddBRRIP72FLeLtADYv bKf/Eruxw6JAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1b+bQAKCRDBN2bmhouD 1xr0D/4psbFJW3Y+ZvRr+dJ/9Kv2CD5E71832DYsB/5J9nwnFqX5pJUSN6brjyaAwpAFHrHXUDy N6Scan0veYW/WmKEriULU8B0e6t9RMCPp14ySZpw9n36vVdlgNxXH5yzIhxTYVDLWQ47tZAjDCG 0dI8+FaZJ3xoYFvoyHQvPKPlaQGHdcsNObvR761iSzvNO9CDfwxcuaaHkifi70QA0Hsii3s7/AR yBvQ9HNN6b51gDuvKw4Qp/5YfQSNsfODPtaGsfGMQk4LC9OQLthVq1KUlHn+tDbwgiJzEPMYOdg ecYUM4ekhryP8HSMPb/SxaoSWnQzilY6Of9lIGcE+JVLtGsL7Shg0WYJxZAz7E6c1sQpnUlXH27 AhSE+mDmNO9EhnqOYDLfagJx5SG6eMjL4OllUwZjhHdbO5K6vcHRI7dm0QzhH5c0jdNrWAYX/Mj JIWppBCZxZ34v72E/SlR32N9b8dlvznV+LNHwDyIbhzJaqRum1r2ipEqkmCxFgYxfPvVPh2wl6o ibtg4z1ukAgmmC3+rY6OH0Czz8AnNJyLG/TGTJ8Zv5/SQQXqID7wIOKEtwPtsY26WtW0mghbz0N riHgoeNc+Shlj/RnrqI7awlxHLdeV3KPnIiL1UXYEyIEGpmY4hrL0d7+RWIqF/SXHCsxy55Sh2H lGpJwmtIfqd6BNg== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Commit 2e4955167ec5 ("firmware: qcom: scm: Fix __scm and waitq completion variable initialization") introduced a write barrier in probe function to store global '__scm' variable. It also claimed that it added a read barrier, because as we all known barriers are paired (see memory-barriers.txt: "Note that write barriers should normally be paired with read or address-dependency barriers"), however it did not really add it. The offending commit used READ_ONCE() to access '__scm' global which is not a barrier. The barrier is needed so the store to '__scm' will be properly visible. This is most likely not fatal in current driver design, because missing read barrier would mean qcom_scm_is_available() callers will access old value, NULL. Driver does not support unbinding and does not correctly handle probe failures, thus there is no risk of stale or old pointer in '__scm' variable. However for code correctness, readability and to be sure that we did not mess up something in this tricky topic of SMP barriers, add a read barrier for accessing '__scm'. Change also comment from useless/obvious what does barrier do, to what is expected: which other parts of the code are involved here. Fixes: 2e4955167ec5 ("firmware: qcom: scm: Fix __scm and waitq completion variable initialization") Cc: stable@vger.kernel.org Reviewed-by: Bartosz Golaszewski Signed-off-by: Krzysztof Kozlowski --- drivers/firmware/qcom/qcom_scm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 72bf87ddcd969834609cda2aa915b67505e93943..246d672e8f7f0e2a326a03a5af40cd434a665e67 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1867,7 +1867,8 @@ static int qcom_scm_qseecom_init(struct qcom_scm *scm) */ bool qcom_scm_is_available(void) { - return !!READ_ONCE(__scm); + /* Paired with smp_store_release() in qcom_scm_probe */ + return !!smp_load_acquire(&__scm); } EXPORT_SYMBOL_GPL(qcom_scm_is_available); @@ -2024,7 +2025,7 @@ static int qcom_scm_probe(struct platform_device *pdev) if (ret) return ret; - /* Let all above stores be available after this */ + /* Paired with smp_load_acquire() in qcom_scm_is_available(). */ smp_store_release(&__scm, scm); irq = platform_get_irq_optional(pdev, 0); From patchwork Mon Dec 9 14:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899877 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF0C81B4249 for ; Mon, 9 Dec 2024 14:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754491; cv=none; b=SRzVHjF4sZ8ugbXnaQmCKJURfUe26M1Vosy/g18EN+Skdx+nzw5wxnwVZ1H6L0riLXgEi+49V/yVVD79pTUtoyjATcoCLXkT7o20oQOW+qf+s5AWZntlfCxzzV5AhShkWIBEm6iko4zvcmXksXqbqWR8Xuo5NejE+rGL4JPrdhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754491; c=relaxed/simple; bh=bXVwUUS+c+N5nd/x0cktMoGmXIjcEO79mBZv/WsAgiA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GTzP0QePTYXeCa3nRn5UY7edQCBVLq0DOofGZ+Imxe6tGrqnKsYHWD3E+zOV8dZu2zll/havpLNq//8EXpvomXz88LCBh7PD44zMPiAkkAkBgjRkHWxhgRSARu1Pl/IymjgvPT+LpNMk4HGspP2yptz2KaZBHuIWSBU8VjhAI7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=IU3vaFI9; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IU3vaFI9" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5d3d69e5b63so274716a12.1 for ; Mon, 09 Dec 2024 06:28:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733754488; x=1734359288; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gQjfcs2sKYpQsUR3dkoS5e986NnXj0KjUS47ud1KCqs=; b=IU3vaFI9XYLY+jB2YeghWWG+n3lJf2wwyaNo+9N6qJMqrmTHgiyF15Y0660XNGza32 Sm9iGWOLSMn5j+ZEb0DaKQw8uDyRrx70E7jr/03ySkAJ09aTop0Pbws09UAegjOH8US0 cq3cwgMwMBJ7MkVvWWmVbvPePUmGNhr3LaXzD02jxVAy/sAG+lwVST2GuTROVC3w4v8G 5r5NLh2ydjTgmnXvlzVaakGoqRNFIcI79C0ZVS1tOKU9FOKNmK6Ro6/5DQSXC95uX/WD oI65YpUuuiiRqor4jiXuZ8j/Nq6i2LjBRnfc/SxzRwvL3f+q/TWw1bLqQnZ0O9HdZD3H qksQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733754488; x=1734359288; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gQjfcs2sKYpQsUR3dkoS5e986NnXj0KjUS47ud1KCqs=; b=Z2Fr1Q4PRbBH1K15PFx7XeaGrZmdpeTjpmfA4tmk/IhJrZjMYRGeGqNUvXaGmCWLlq dVeDOzjCxn3scI2AffbPcAl+Gfr+irQSjoVj8jr0nDR05IEso+yOFS2ERsSv5eTpZ/pH hX84m3OVa/Ouqlcb2RPrySAP+oebpC4n06ys4A3tP+2hlvlgUfg8T/BVW5VUmVUeZT+i RbaO3/i7/tPI3HoBF3W8v1cQ0fuKdAKMzM3x1ovY2xyvgOSoW3BLfuB569vjgnAtQAaf vJANaME/w+F9jy+2M0x+L/TBiZgWAtfhbOUezr3H2HLPYo+ZNx9C/C7eDAxe0CNEn3RG PFHw== X-Gm-Message-State: AOJu0Yzqu5Liu1ZI6PaOUU3KtDwtPMUHlXNTuwPkwaoGHW/EQuxiWDjQ ywXBrPHYyMEKrVelvkNLBdQB7pyFsua2OOgOfdIIl2kjHv4YHpBUIQiSEZKhDQr199sOczgv8wa x X-Gm-Gg: ASbGncueuHzcv+XsqomhObZ+LYfcoHrmgw+TJ8B7Sik76x5K6zroq7sYT6uTgdTCpjV 08vI/5BTcfZJeoctCgNGsOl4MSerWR571NTw0lvgEpVUsl/mYwUaB2ilzcUHf/nzj1T8j5l3ykr gxyKF6FaaAhGmrAUjKDzbq32WmaeRCN2drl2OtctUtK0IbA2XMDQwhcVfquO2wIp5d2X+Jg+G9z OmW2N4X8CIlKZ4BhejYPG5F5PjQVXS3SJkqvnrVOtgSgwm+bZ9HwUuG1NPdc2IqxA== X-Google-Smtp-Source: AGHT+IE3RGJa2VRCqJMaJ+Lhq6v/u63fkKtlHSC8vuqVBVwcK2u/Be4KhKB5cdbTigwywznwhJ5WdA== X-Received: by 2002:a05:6402:51cb:b0:5d0:bcc4:8af1 with SMTP id 4fb4d7f45d1cf-5d3be462850mr4743547a12.0.1733754487524; Mon, 09 Dec 2024 06:28:07 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm2887141a12.42.2024.12.09.06.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 06:28:07 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 15:27:55 +0100 Subject: [PATCH v2 2/6] firmware: qcom: scm: Fix missing read barrier in qcom_scm_get_tzmem_pool() Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-2-9061013c8d92@linaro.org> References: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> In-Reply-To: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Mukesh Ojha , Dmitry Baryshkov , Stephan Gerhold , Bartosz Golaszewski , Kuldeep Singh , Elliot Berman , Andrew Halaney , Avaneesh Kumar Dwivedi , Andy Gross Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1652; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=bXVwUUS+c+N5nd/x0cktMoGmXIjcEO79mBZv/WsAgiA=; b=kA0DAAoBwTdm5oaLg9cByyZiAGdW/m6g3rABh5shDUgjU/soyymq+TMXJ8TFB7jZg/JkOKV5w okCMwQAAQoAHRYhBN3SYig9ERsjO264qME3ZuaGi4PXBQJnVv5uAAoJEME3ZuaGi4PXgkAP/A9+ 9P6Iwv9mNhA3OiZh5j6FG/JhMIO/suJ8Rifu2WMhiHjQ3ChhoBr8GJuSzHkMruggY9lO6xcYFMB HeE7lSzT3wvutASuNPD/7Ez6h+Zvv4K7IUZPSYuPxsMMj32hpdh+JvyIU3gVw9af9aFMPVKBf55 2hUSZ9PcpTQ+VQmVtesqoKvqtRb2ZyNT+UGAy6G3IVpwxZXRCQLwdQsrVCD8PDuCOpQPhRkDVWe JsrLqwxlRzHoAy1RZtEPRS06q0U+MZJj/ODxOPh2coJ6JUXxdr9n7fTjJlfjxHY8hroDfjFIhgg eIpsPQklLqllENdwvZB+AcTcAiO4eQeZpFMljypYjSQscUNeKNKsY0jgJE6MuIinM6qkzJVbG4x IhaZW5RU01/eQaXUZoVwSlJWi09hseuFLs4iSH76nj1qcSDhksJi3VwOAqXGw3drEru26lnDefb MgnTK7IolNwMOpLmUhlCYZs0c+CwR9j1QlnHQbTp0/RjJA+ZfM/u2kWbVl/AzjGfkr7vM8cKHLv blOG2n9SO+EbNBvutNOqVke+ey88zWhbmfzOR8Utjyqpk+/OGatfM0h6DqE2EWJAvBkIzZWMw9m nTJpmjfwNnjn3D4hFUZmXv3h5YrLvwvfm6oI3dZ65eImlLLInwlIhlbR873dv4lgn0vjr0ww1nn VeGlP X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Commit 2e4955167ec5 ("firmware: qcom: scm: Fix __scm and waitq completion variable initialization") introduced a write barrier in probe function to store global '__scm' variable. We all known barriers are paired (see memory-barriers.txt: "Note that write barriers should normally be paired with read or address-dependency barriers"), therefore accessing it from concurrent contexts requires read barrier. Previous commit added such barrier in qcom_scm_is_available(), so let's use that directly. Lack of this read barrier can result in fetching stale '__scm' variable value, NULL, and dereferencing it. Note that barrier in qcom_scm_is_available() satisfies here the control dependency. Fixes: ca61d6836e6f ("firmware: qcom: scm: fix a NULL-pointer dereference") Fixes: 449d0d84bcd8 ("firmware: qcom: scm: smc: switch to using the SCM allocator") Cc: Signed-off-by: Krzysztof Kozlowski --- drivers/firmware/qcom/qcom_scm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 246d672e8f7f0e2a326a03a5af40cd434a665e67..5d91b8e22844608f35432f1ba9c08d477d4ff762 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -217,7 +217,10 @@ static DEFINE_SPINLOCK(scm_query_lock); struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void) { - return __scm ? __scm->mempool : NULL; + if (!qcom_scm_is_available()) + return NULL; + + return __scm->mempool; } static enum qcom_scm_convention __get_convention(void) From patchwork Mon Dec 9 14:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899878 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541BE1BEF85 for ; Mon, 9 Dec 2024 14:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754494; cv=none; b=mD8CNnOBMNb/mwFy5yE1GxYA8tFScFOVtXC5rLLDlDx8Wo01Sx/O4VtN2VssGanWVikioRR2K8nl7pcrUD/yaqfmHK10WFj3GjIy0aVTILKPmFfQfFFRBgHAtZcZNoW9PLuhJMl94p24yQF5eRV5s+Gc4sWas0hepHeXcf4Zubc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754494; c=relaxed/simple; bh=+bL1C3+EqmoCZ+3NSkbD7ohn35NupzZbKWkMvdBYXvo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R08NCPLlvP1RY+tdIFzErHbGFYVL7HDZ5/oMIyrG4IqRSUor+mepiRdn4Ie39XK8skn96Wkke7X0IbDP8l3YJdkZ8psL1vKufnuUHI8HaiiuQsZALin7RhzRLnzY0teMjNWSe6Q7MhXZnX3JyDWe8R3IjjhPcIa0myfZ/C5Avc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=bUiVqrU5; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bUiVqrU5" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5d3c1f68f1bso308158a12.3 for ; Mon, 09 Dec 2024 06:28:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733754490; x=1734359290; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XGnb+IQjlD24kYzbmGgtXKwZCCe15sEsS5u15TpXOMs=; b=bUiVqrU5gcg/8WCYYP0oNHDZU/5gu71ixXr6JNkvi+p4fhIIzNl9Mr0u+utsvGw6DA EqR/KoP4kSe1h5alEBPbKoF6p6DxfVj0ChsAErMWH6nCj85k4Ozu3nYHYT8lNsXfxLlO Ja+lu7xKkWTY0rdxJPaaqxGyVZJlNX6WoAltjrME8+btX72qcC1D2g2BnXCIWihfZHc0 lvhxorLnMi1GqDkzqiYcPCtgJV7MDDQ2AcZnlC81ii+zVPjtnW1PXT7rYLzZ/YX6RtS1 banTNtauRWNYirQBAGtWgLwTmDKPjgepxx5hQ02NdH1qmRGXONuc+CMzHiCa2gjFb2Ww mp9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733754490; x=1734359290; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XGnb+IQjlD24kYzbmGgtXKwZCCe15sEsS5u15TpXOMs=; b=uLynbiJO5WL8ZNa3qaRf/GVMTHNFdNQiCdRvrG+7HIVBtGc8McfYbmJJsHcQAEby4b 4jbgvPEXNHXuxH9J4d1QJZc+gxo9oIRr7cdem9K7n/Y7s0h42bkeiSAqiJ1nuScRuofz InGQoJ67BF7DfAJxCx2E8CBaxUOFQoW7WAJolds8BZ9HTpfMC758gCi5rYwcNWNs1TvN O+Wf1cPDM4c8lkZm9cKnZlgzTweT3r1Cx0k/RYPxiMVO6uk4O4pWgSjKTkoUyWQbaM06 QljIZ2lIkD4K8YB7kdpGjgE8I7PiIeMu+lV/P1OGGBjBq416EIS38WHu9VZlptATDIAb 8Z2A== X-Gm-Message-State: AOJu0YxLH5CBcp+yhwQwyvF2EDWuo7FG9RdjbE5hx2xBYgKbtFLQ/5Cb FUB5g0JgWvq4c9Mak5mUHJQ5IM98mTJLSaQqy+GaqxReY/HaSKbYpfuiXYkbiOKZk0Js6eZGX4s X X-Gm-Gg: ASbGncvwO4NQmXbwXOmPn1w2aGtz3X7jnkJ0D3sG67XRZ8EV9bKLWTMAaRxYH6hdBHM B+oPeAxAmooTJVzsyBHKSbMzNtMiDwBziDdAYTPz0N6qbgG7HeS97YaNzjZU9vglgZ4Ke0XSAuJ GcaC5J6IZF7hfV1Z+P4hS6TPKwT4ic40YyCkJnHcGKlqdTDzGC089A1T7yn1RM6URLWzaZsEcLa tLmlNP+g6/GSAhRB4gykHWj8UUJlDNR9lxXDoqP8tmFBZG6UEfzgWu/q8DsWAepjA== X-Google-Smtp-Source: AGHT+IHgFy5jwj3ZZsfJHP5oyOrDc5Q3gesJdagWrryrrmWchcTc/iUsAE5cQ2IUAPj3AnV8JRqIyg== X-Received: by 2002:a05:6402:5106:b0:5cf:6635:858f with SMTP id 4fb4d7f45d1cf-5d3be6d6a3dmr4807719a12.3.1733754490094; Mon, 09 Dec 2024 06:28:10 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm2887141a12.42.2024.12.09.06.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 06:28:08 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 15:27:56 +0100 Subject: [PATCH v2 3/6] firmware: qcom: scm: Handle various probe ordering for qcom_scm_assign_mem() Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-3-9061013c8d92@linaro.org> References: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> In-Reply-To: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Mukesh Ojha , Dmitry Baryshkov , Stephan Gerhold , Bartosz Golaszewski , Kuldeep Singh , Elliot Berman , Andrew Halaney , Avaneesh Kumar Dwivedi , Andy Gross Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1373; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=+bL1C3+EqmoCZ+3NSkbD7ohn35NupzZbKWkMvdBYXvo=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVv5vnIllq8kxBhdiVODsdx6QNBhfih1LR0aj8 VDXAx3dVzKJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1b+bwAKCRDBN2bmhouD 1znTD/0TcLa8dg9E1O5wu1+l5cUms9pve6al9nhGVpkYOhyLhPq9JcQWfzIpgXuz/Lo62Objr/r o1MygFPFO9/rb2mRDJL+TGbgbVwj9rGCsAayUHwZ42hScMdmCJ3POaoImDTZujfMJ/Ltddmka9I w7/79sQfl2GR2WKrHrg2iEL6sLS2P682FaQBQGYfftUwT+N+3IHaUoCJ7a1iR3L59gI5FsII7j4 8qJC0BJB/RvHTTd9Dp+kpqya71zI1s2f/d5/NFgANUFclRgjJ0CEfPy7hZqOx//5X9AiD0b8zLn QElijFsE5TKRmGT/b7MRaU32VMgdE9T8ET4xk3KgieELnmN8L3ij4ZaqMX2vCAt/Awv+Gdh0sNT Pch1/EOIIP9ZT86pFeETnskutIFCdqLGgZ57dcX1CynZJdAi0YqrpQ70tQp2WNF10CQryvCynZp ifldt7g+9zTNY6rwkdl9yUXw7lUhQ7E2e4z5X7nYxE+zTVmBZdO7W2fsw6WWTnWNzAogZKlzwWx YoMG+RBvvtc+f/UulqSNpD0sGUajEUf6nvi/l99CTBEdXBCNBGnp6Klg3xGpysy5ehIEQ4Po13k mypwIBSLQAuVbmMso4x9qpGHyy94fC+LbUcq+bdig7t7ngR9LpAZNp36V0PcXr2utfmLWOB6pW/ pYio2vbG8wn48qQ== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B The SCM driver can defer or fail probe, or just load a bit later so callers of qcom_scm_assign_mem() should defer if the device is not ready. This fixes theoretical NULL pointer exception, triggered via introducing probe deferral in SCM driver with call trace: qcom_tzmem_alloc+0x70/0x1ac (P) qcom_tzmem_alloc+0x64/0x1ac (L) qcom_scm_assign_mem+0x78/0x194 qcom_rmtfs_mem_probe+0x2d4/0x38c platform_probe+0x68/0xc8 Fixes: d82bd359972a ("firmware: scm: Add new SCM call API for switching memory ownership") Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bartosz Golaszewski --- I am not sure about commit introducing it (Fixes tag) thus not Cc-ing stable. --- drivers/firmware/qcom/qcom_scm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 5d91b8e22844608f35432f1ba9c08d477d4ff762..93212c8f20ad65ecc44804b00f4b93e3eaaf8d95 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1075,6 +1075,9 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, int ret, i, b; u64 srcvm_bits = *srcvm; + if (!qcom_scm_is_available()) + return -EPROBE_DEFER; + src_sz = hweight64(srcvm_bits) * sizeof(*src); mem_to_map_sz = sizeof(*mem_to_map); dest_sz = dest_cnt * sizeof(*destvm); From patchwork Mon Dec 9 14:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899879 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C9791BEF98 for ; Mon, 9 Dec 2024 14:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754495; cv=none; b=aMxi5/wU0YdK1m66wLEMvK7DEgAJqUvh/xIfrhrfdCdKO+E83HviNPDW2GGED262eRds/kK+3pH5NOppz+m9d7Yqq3eSBSY6Mt4XqjNhmWTpD/OLwbDIpbaDPTiDWlaIkGseIyivI8Ld7uUfWEkwv+Je+39R0Ux8DAtR7ZLZQYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754495; c=relaxed/simple; bh=4Pncka7UkbqC3Kr6dTBYDaYj7aCk4aNWEEI0msKMVYU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BXH4eaWEsjS+EiIBFxj9fmQsYGSgMKRnYwGNNVSbcQ/Am3s9APHhB9u3Bn3Azg46jxQGroBGl3/0UQPmU0TwPs28zQBUaJEdYnGJ2JVfUZTcZyyHEKoNv2x4k9ZJAX27ilkt48X6wUZvKU452riDz4EmkfPq72VbuXL/imZaLYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=sb7Ab0Jy; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="sb7Ab0Jy" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5d3d69e5b63so274731a12.1 for ; Mon, 09 Dec 2024 06:28:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733754492; x=1734359292; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LrcZWTWQ0k15XJUbH5JtpskXN7f1upsgnsfnkZdegjI=; b=sb7Ab0JyFnss/iVQCSkJSGTHY50aqNog2qntEX2JxNaC93MAxmY7eQIVOkbI8Yk+Rj ugNDm+5ghERCSyM5wUR3DybTEZ0+EiOrBok32J1qPh/gmjHKx4sWjju/QydXBv0d03ZO 2gPaEK+81WgvOJgCZb9NWKNdSIEPfUUulQWPS18qRbp8JVpWAkHNmNF6Xi8dgAIUzo6Y E0D42nrsmN5/vb2SxANXBekHIO7PfMPM3x1EupJjPfP/kKonvll3fh4wizmHx5d5YSBL i5C+1HgMftpemHqirWfNvrqaNiTQLL4bqigemP332OnkXvqRPBFmdPi9s7Ii94glOkgL WYWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733754492; x=1734359292; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LrcZWTWQ0k15XJUbH5JtpskXN7f1upsgnsfnkZdegjI=; b=hKEH2IMgjr96XzhuG8FH5MM1UeuLgCd5GYU49wRcpsuCDA6qHluGpazXein51+iAn/ 12H2NbSbzY529JjvAUMg4+snHnXwKagW4UGS2pVdublyyNHSC/KbrjGgBr3mqnu31Mff XnUukdMNdspglXTfeNmYX4V1FhY0oFjQPzB5ZytVioUs0mFPosx14Klf0jJaNreqtpF+ sVB2tabAEuLL5UtJbhGKk0NbQHh18jViQHCFLY5e9N6daJm0ppGcFXGZEUgtduOYfhtq /pqMdD58njRfy3Eis3dPdzTYWM/G0zYnHtkPPMmxAiRh1uNyREJYqD/GeBstQJmy3Bbo TVvg== X-Gm-Message-State: AOJu0Ywtkr8eiwO7W4gj7PStPd7M1kOFQDEq5YlnGR5HuwX+BrC0EpKg 95kGKBrL7kAlcC9yN1YbS41zoi9KDUeGm/gpziyIMM+XNcSR+OmOEH8J0bE7rWLVy3OnATOvCPG V X-Gm-Gg: ASbGncsrUJF2c5iRLD6zmShBsyyXY8iywIm8nQ0flWqeEvNDWG4/D+hMHVMQ2wnvw/j qlp3T3aRi6IfkHEKwRZWo3uLQPzeacns4u3FqFeR40oNP8v9ZB2xU8UHDrTpFeGOCSwhj9JMXu5 ITvd2/8RTSBk7dse8Nunm3BiQB90ZN4cLUmmsnlgu5AHbVGCrpdNCjDyZcbDeX3RebXO0fjEwAO DRTSo5MK/xAZpe2LjehnsdSOG5rFpa/wz4r1vcE/LINpO8M9IB1CgKRhpfLWd6Waw== X-Google-Smtp-Source: AGHT+IGIC4nihlegOu+zGJNRmS1inLtFDYhfYoyLnPOcGjTxisgrxlM7itNNq6OP/G6KrPRubQfqmw== X-Received: by 2002:a05:6402:34cc:b0:5d0:e852:dca0 with SMTP id 4fb4d7f45d1cf-5d3be81e011mr4688593a12.11.1733754491700; Mon, 09 Dec 2024 06:28:11 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm2887141a12.42.2024.12.09.06.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 06:28:11 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 15:27:57 +0100 Subject: [PATCH v2 4/6] firmware: qcom: scm: Cleanup global '__scm' on probe failures Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-4-9061013c8d92@linaro.org> References: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> In-Reply-To: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Mukesh Ojha , Dmitry Baryshkov , Stephan Gerhold , Bartosz Golaszewski , Kuldeep Singh , Elliot Berman , Andrew Halaney , Avaneesh Kumar Dwivedi , Andy Gross Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3735; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=4Pncka7UkbqC3Kr6dTBYDaYj7aCk4aNWEEI0msKMVYU=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVv5wKJ3snnQ32fKmGQYLiZQPLTv8ECJLqCGcu p+OThngBuGJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1b+cAAKCRDBN2bmhouD 1znjD/9qFOmwH7EqcgmSmws3GrBG1kNHApje+Hb6f3HSbGA6xwTpY4a5MCKp8puH7byva5VWb8X AlcUBNdSw0I05Ht453ijS58bi4em89CRfewtVIfoIANIWx9sBRr22ncb69geC1BBdVM0R7oXWR3 iqorscnZJLpBdtuHuBIHPy4l4cImbcXQ06T9t9EchU6hygspsy45zPryfElpKZ/J0R/rjR8mu5D DFSDkjIJ51nZxjx7flk3q8TMy5P4sURMQMiVJ0UL+vVrxkjfx2hBo+tupoyKBpgi2FDWs8SoE+g IlSXK90rzqGgYlVZYH4mv5oUOH85s5+bfaSRZ6zBBb+3K6blJOI7IiuCwZt8wwmI+76F49y5tN4 TH2s5uTmHLpY+mqd/AWtNl5TekyN5zccQ/7HVDvIGoMo8LWqpYaCb0mfMZwJYMltyIyhvR+5cCx aZUHsozwgTf0Nt2LriuKgdgq8QmN9Rlv9O+vtNBJpjHUpUjvJbBsXSx5G5WfgMGNyL2Jxnfirjn +O4PeEYzFdBpjOyAl6aNMuGrV/+fKOEOFIvxL4OHTjxbIPWPoY3MM+z8ggX73N5aQKiezJ8kX58 bnrAk9V5D2bwp3ZOtnsh9lDWR3PQS1axlCHpY1f883pgv7bZjH+JfBLRGZx4i1vzmh1r8GaRA0U 0EGCaQ+oLJbsryg== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B If SCM driver fails the probe, it should not leave global '__scm' variable assigned, because external users of this driver will assume the probe finished successfully. For example TZMEM parts ('__scm->mempool') are initialized later in the probe, but users of it (__scm_smc_call()) rely on the '__scm' variable. This fixes theoretical NULL pointer exception, triggered via introducing probe deferral in SCM driver with call trace: qcom_tzmem_alloc+0x70/0x1ac (P) qcom_tzmem_alloc+0x64/0x1ac (L) qcom_scm_assign_mem+0x78/0x194 qcom_rmtfs_mem_probe+0x2d4/0x38c platform_probe+0x68/0xc8 Fixes: 40289e35ca52 ("firmware: qcom: scm: enable the TZ mem allocator") Signed-off-by: Krzysztof Kozlowski --- I am not really sure if authors wanted the cleanup at this point. Also, I am not sure about commit introducing it (Fixes tag) thus not Cc-ing stable. Changes in v2: 1. Store NULL --- drivers/firmware/qcom/qcom_scm.c | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 93212c8f20ad65ecc44804b00f4b93e3eaaf8d95..bfb925586e05f7d3fb7f00e3d3d3eae4e35f39c0 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -2036,13 +2036,17 @@ static int qcom_scm_probe(struct platform_device *pdev) irq = platform_get_irq_optional(pdev, 0); if (irq < 0) { - if (irq != -ENXIO) - return irq; + if (irq != -ENXIO) { + ret = irq; + goto err; + } } else { ret = devm_request_threaded_irq(__scm->dev, irq, NULL, qcom_scm_irq_handler, IRQF_ONESHOT, "qcom-scm", __scm); - if (ret < 0) - return dev_err_probe(scm->dev, ret, "Failed to request qcom-scm irq\n"); + if (ret < 0) { + dev_err_probe(scm->dev, ret, "Failed to request qcom-scm irq\n"); + goto err; + } } __get_convention(); @@ -2061,14 +2065,18 @@ static int qcom_scm_probe(struct platform_device *pdev) qcom_scm_disable_sdi(); ret = of_reserved_mem_device_init(__scm->dev); - if (ret && ret != -ENODEV) - return dev_err_probe(__scm->dev, ret, - "Failed to setup the reserved memory region for TZ mem\n"); + if (ret && ret != -ENODEV) { + dev_err_probe(__scm->dev, ret, + "Failed to setup the reserved memory region for TZ mem\n"); + goto err; + } ret = qcom_tzmem_enable(__scm->dev); - if (ret) - return dev_err_probe(__scm->dev, ret, - "Failed to enable the TrustZone memory allocator\n"); + if (ret) { + dev_err_probe(__scm->dev, ret, + "Failed to enable the TrustZone memory allocator\n"); + goto err; + } memset(&pool_config, 0, sizeof(pool_config)); pool_config.initial_size = 0; @@ -2076,9 +2084,11 @@ static int qcom_scm_probe(struct platform_device *pdev) pool_config.max_size = SZ_256K; __scm->mempool = devm_qcom_tzmem_pool_new(__scm->dev, &pool_config); - if (IS_ERR(__scm->mempool)) - return dev_err_probe(__scm->dev, PTR_ERR(__scm->mempool), - "Failed to create the SCM memory pool\n"); + if (IS_ERR(__scm->mempool)) { + dev_err_probe(__scm->dev, PTR_ERR(__scm->mempool), + "Failed to create the SCM memory pool\n"); + goto err; + } /* * Initialize the QSEECOM interface. @@ -2094,6 +2104,12 @@ static int qcom_scm_probe(struct platform_device *pdev) WARN(ret < 0, "failed to initialize qseecom: %d\n", ret); return 0; + +err: + /* Paired with smp_load_acquire() in qcom_scm_is_available(). */ + smp_store_release(&__scm, NULL); + + return ret; } static void qcom_scm_shutdown(struct platform_device *pdev) From patchwork Mon Dec 9 14:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899880 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F11B1C5CAF for ; Mon, 9 Dec 2024 14:28:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754496; cv=none; b=JiO8hkgEGCVNLpxsydM452xU7XJIBOoSEdfORNoMtBQtrsjysz9W6MPZmnnZwGR2qgYKYJK2f1vissWkzd8JR1j0vW+O16vXPnJZ3dAUFgc2IVfdWLLPpP6fKcdR9uTIT+PIzt3N6pnLQB2OYdawHr02ci3jGGuDIHE5I25khsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754496; c=relaxed/simple; bh=5TLlUUFMlxVBRA9LfgfySqW4/f430JBLZVgZXAnTFfw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ScuHxvQtF/PG3zuFl3EJ25XxJS8YEhI5NhuGGPRcF+LDJz1n5safPAQLrwQutuXgCvZIEZTOzj9TgKmVWQBFAdZg8spBJ2e7QXk9YoPRDVp9hYmMNpoSQvk8rUPQ34R9N11Gx+4vyZHBWx9DoHE94qA6ohhAglQQE0jmgknU9kA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=EYCfjxXq; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EYCfjxXq" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5d0b85c5574so471686a12.2 for ; Mon, 09 Dec 2024 06:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733754493; x=1734359293; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=krw1ZM4+VGT72qR1TvdXm8jH8NeT3h/uE5f54vAoMeM=; b=EYCfjxXqTs48ZuRdDdZlVdxSLs4pnh1JVDZsYThFyiSnTKZQLB6LcDCQTjTxPlQ0KE B6+Zc4pxpujf+1W5kGwS3wuRYJGaUd8cTVHxCWQfMR2CJapcnheMoLWzlldQYgV/wTrW dE5ye3LDwG0MXWc9x3QzJornxc3DGtB1K9qQSqd/t6Y/YMIVTk84djmaYH7FrnfLWGXH YZ6/RYucxW9WsC9G4Mp/ae77XLCGyy2gL9JJ83Xx24M9wsVxKfCwNNAVCSaLecs1EUzV iLrDexe00Q5tP0/K1U2k+gDWyfNaHsbuz4RINl2ln3FzoqqNv+mjvNucxoFWYffcqYiY Zwow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733754493; x=1734359293; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=krw1ZM4+VGT72qR1TvdXm8jH8NeT3h/uE5f54vAoMeM=; b=E9/Dgi8Xu8xXy1wDNsTPFHr8olWKIT90X9+PmzLLfU0IMrdP3lUrmqiY3spJZO/QD7 OlKYABikfVTnPT3NtNVfDk17onhjDravydnStuFVDkM38QetygiDsk6aqvgsbosgs6S+ fTPWQuWzphZ50tKNLMlAWSNUZ720aWi1qG0XsyHYSWxl2XwT78zEYcNnYaPZu8uuPA1P jBzw5g7cQPrsdq4XDHKV9k/RNal64AATxBCJUhrGqRlE26uTattZ7iSk8Bo+MRv4K2a8 a2lKN69TMvAiPm0Mf85dGxBbVK/8DEIvcSUun4/7ZhpzblvSEYJcCPb+U0Mu63lIGk4n +QMw== X-Gm-Message-State: AOJu0YxNe+TI5mYidYoELa6emaQ1jGotBOEq1ZgP+UojtxkQASXLkbQk leNE0vwgS19Vy8olZtVPfS+F/jqSy+rHipU8CPZZOdo19NzbtPUR1z8EIaiD3p4Y34SMPtuiI25 3 X-Gm-Gg: ASbGncsGQDfTXl2yKQ0TsN3rlVXuDZIMjmWvKkxFXK4ZL22dKIMUoWQEe4/wVUkEt9x VIUd8pMVolSpnskodazoRoZfPBUyhTHGPEuLR4JcPdyWWtrYn/7QuxB592Mx+N+uMISj6MsMoiK OWxXi+xPOIuUqOUDPyW3zWDqvZ1i9xLLnLgJzb7jEt6hybNdZReV8ads9bPM/EYmskdzkCA0HUJ 79I2EPe0BTbv93bm+u5b8ChzofzUVcXMc8SiRzKqkOby5uoKGDIrXgrslIa+5i7ALCFvg== X-Google-Smtp-Source: AGHT+IHsI6iD/zVuMNM4tw+NA1uwfnkpW2LIFQgi41uLoAMlI78UMHhZxLJfaWOWrR8bA0DyMV1lKg== X-Received: by 2002:a05:6402:2349:b0:5d0:d786:b87b with SMTP id 4fb4d7f45d1cf-5d3be7a104fmr5033011a12.9.1733754492988; Mon, 09 Dec 2024 06:28:12 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm2887141a12.42.2024.12.09.06.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 06:28:12 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 15:27:58 +0100 Subject: [PATCH v2 5/6] firmware: qcom: scm: smc: Handle missing SCM device Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-5-9061013c8d92@linaro.org> References: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> In-Reply-To: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Mukesh Ojha , Dmitry Baryshkov , Stephan Gerhold , Bartosz Golaszewski , Kuldeep Singh , Elliot Berman , Andrew Halaney , Avaneesh Kumar Dwivedi , Andy Gross Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=985; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=5TLlUUFMlxVBRA9LfgfySqW4/f430JBLZVgZXAnTFfw=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVv5xgN8900fGfZBc1qQpYhJH5p3sIki/V9+Lo jHqa9tcWb6JAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1b+cQAKCRDBN2bmhouD 13zPD/oCh6uonPTtF5PRZdZ8CbQ8c3GPgUXKd43349iH2p0wSErBDh4pob3eZb3wYp2L03Dzi3b mUnaOtKGWEVwOhAN9tKH02KoqHPJknxkBefYLUMXAKnmxC22i7WfgXwTD32+OsUF2kw5TfKCZ9L t1+sYYMbSA25pdAamsN8nxnGQ1UjgnuYL9rzCsjbDAcV29N6IaX9bhF6Tw9YLnFswXZ8jTvYQbC go8dSYEkym2K2Y0fOftlz1xtce2sXMEckDn0t5RFtVzTg1h4k987E+dKG8PSd8sCEgvvQBsQRKp aeEdlnGKNxw7IQWYRUm+WP0XVypLXmRt+yVMQDd/g/AuTAQd0m3kM/tR2WXcI5Pb1KnFLD7WPQO WxK+4Ln1ohCa/dPuZWp01LD3D4JuXYMUQtB2CSI1pCeR4deOwnsCKwKPUsi9mB5gNvsAhniwwVF 4G6MMh2QxkdEirYDNifzUZHmVefA0TwjV2UbaOKTMqdVWq+ycAU/7ibt5gYoZeYu8zXf6ED6lys Pm4A+ZNluStmTGyTnx4J9AdMWho3B78f57+MnTyLFGxpDJ+5O/khB5wKdjEpeqD4aoq/r3Xx6hJ 53ffB1rCj03ormMApr46JHHpXgpK6TgC8Cd1pg8fnUH3cjLkqZNgOKtr4NW7/2k/ucTGopPwvuF JDWGudroS+bxvwA== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Commit ca61d6836e6f ("firmware: qcom: scm: fix a NULL-pointer dereference") makes it explicit that qcom_scm_get_tzmem_pool() can return NULL, therefore its users should handle this. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm-smc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 2b4c2826f57251f25a1bc37c3b467dde28e1268b..3f10b23ec941b558e1d91761011776bb5c9d11b5 100644 --- a/drivers/firmware/qcom/qcom_scm-smc.c +++ b/drivers/firmware/qcom/qcom_scm-smc.c @@ -173,6 +173,9 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i]; if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) { + if (!mempool) + return -EINVAL; + args_virt = qcom_tzmem_alloc(mempool, SCM_SMC_N_EXT_ARGS * sizeof(u64), flag); From patchwork Mon Dec 9 14:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899881 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98D351B0430 for ; Mon, 9 Dec 2024 14:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754498; cv=none; b=iT6kmjEO92BkweO8fvkE4etDO8JoFFQ78zWzf+yVy1DlMoZ62DK8MpzQkyEHz2xA1T99XZygGfpemwVC4QhXxWc3Y3A9JywX1n0gVKIZdGBPdDLHL40wFBuhTyENd1SIuytw+RVV0/8VOBXJxTT471lqV75+KfRgftZAFTVnHT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733754498; c=relaxed/simple; bh=m0JRt1yAWsfjNKbVlgVQYTxcRzJBsIOwhATVf8sbhII=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OANriAHq8Mcxyp6m+GGBCljCbIJ2g4LVpT6UpBnk+uH9k5KRTAgGncsfzC9IrTjNg3mfgSery4ac0wZeP6BoKFwjjvL3N+h/a7cBdbCDipyHDPhumVr7skrzmdbTtDHEQ8gDIrwg/J56rcz1iDVRtbtCG/8IjHSrQn4+FCDfQ3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=S3y7NqoW; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S3y7NqoW" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5d3c1f68ef1so536760a12.1 for ; Mon, 09 Dec 2024 06:28:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733754494; x=1734359294; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qpF4sxmPjFaBMoIz7MrnksfqhjJBtk/BSNuz7mOTvt4=; b=S3y7NqoW8mwTWrzJenAGRaMoLeNkzpI+9kMC2Dozwo+n3pGcNCafxFzWjUZG7itP2W m/ZJwdJvb5TZNJWvric0uGn144GSQXS+tXTLoA3MWDZWD7CZUoMI/hDuEqL0xVLiIb6q pvUvmdxqUZNLZZSmvSJEisgnTm+gbM5MSKMPF6wivnZHExIqWBCIqlGkcPDLMr1erhWO t7S9X8XEnE8oSoDQ0kZMebvQErTLyWZNkYYWr6shVg6ReAX4vWBG8eU19/cZvAnJhkWW Lys80kO2ktgn9Lzf05kCU28HFJKQc5WJR0hLwtNvmi6RS7qiXBfb8tUnYnHCgSk0syBu hpEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733754494; x=1734359294; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qpF4sxmPjFaBMoIz7MrnksfqhjJBtk/BSNuz7mOTvt4=; b=JJhXvjLFrhfswVjZiDZskCXExAc+mc1g+q8WIfnz9c/BqoNFNt+Y8vVJT5VPhVJw+a OFyEdpuUjkMkFEJxlWFFpjUe3RqVwbMaMBWT377rwWl/lJTeKcgtWORIc/yiX2cc6ad9 GlwAABexW8s9R8l4b0f+KwQnAa256Q/4cli6/OHjHTly/iOCKRjUpsZ6CnlvwyKznPO4 gkTGtNdFYiczmpDjyLwHJYjhnBWxbz0j5x3UTrnL03QHFJZl/DRnMYEWhuI881Bjl2u0 XhIEvj/+lJ1wgZ1gF86qff6vcNx6/f0txhVjFnZSmXcdCPd8cOsHE0JiCexGzKNiWPTi OvPA== X-Gm-Message-State: AOJu0YxZbzrkgvVfX+gY5yAODWs4WBJ2GntYICfjIT8EkovWNoEO4KwA UxNJvWdBinJBVTR+4JLp+H8o/bvK537YPcJui9dygR9IXHZYraGxSVy7hAaQx9ntN0llsB5Ju1k h X-Gm-Gg: ASbGnctfwWagwjtFbXwQNZAUIaIsJSQzWz5yheniBDfqXDS2DhfMjFrOHT83ts6NxO6 2D8/tMUGhTrELPb4VvXj3hSdMbls06w5IM4YQx62+7guyqJMmY0xTGHPY6weZ9I+213uvZEm/Ra mZekjYLtvlnxk7Vqh4ce4yqlEdwGQ5kTmABGLXFH5JM8gQPqiYjMoYuLMEzezhlY1hkxXifHwTC rhRMOwY1Mv/OKXDRPzmQF9v2v5cyS2PGzOcos8w0qi4IkcIMT/+YNQtWwt7/w47Jw== X-Google-Smtp-Source: AGHT+IG6hfXrt3hvSblfYqRULX6DPNyKDKRfmtd5xsNKFaYDrZhdtBXI/mAT7EM8nZSdNRA5dztggg== X-Received: by 2002:a05:6402:51cb:b0:5d2:7356:e0f4 with SMTP id 4fb4d7f45d1cf-5d3be6b1320mr4599602a12.3.1733754494536; Mon, 09 Dec 2024 06:28:14 -0800 (PST) Received: from [127.0.1.1] ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d3eb109bc9sm2887141a12.42.2024.12.09.06.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 06:28:14 -0800 (PST) From: Krzysztof Kozlowski Date: Mon, 09 Dec 2024 15:27:59 +0100 Subject: [PATCH v2 6/6] firmware: qcom: scm: smc: Narrow 'mempool' variable scope Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-6-9061013c8d92@linaro.org> References: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> In-Reply-To: <20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-0-9061013c8d92@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Mukesh Ojha , Dmitry Baryshkov , Stephan Gerhold , Bartosz Golaszewski , Kuldeep Singh , Elliot Berman , Andrew Halaney , Avaneesh Kumar Dwivedi , Andy Gross Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1314; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=m0JRt1yAWsfjNKbVlgVQYTxcRzJBsIOwhATVf8sbhII=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBnVv5yGQauxg5c5bYfzNG8tu0ldbo/Dw+zHJn3E 83ron6hYf6JAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZ1b+cgAKCRDBN2bmhouD 17jfD/0b/dA4aucjMR6lx7H4ZacY5FDvdKUBfKGqITx0jWDckMCN696DAGVLpTk3mGRY6LNui/y JwRjzqvlrzdveRYAUulCfB/d625LkXA2MpCI1+VW7PUISAL3jW4Sjk0vLzB/nNd1kG9fYflVaSM 2BbhOoOs2SWQYJGcec0a9/TtdWMS6ZNDPdmEFt9hsoQuuwf2VTTrevsByU28FN7lL/KFIKYGdiQ GKjdTZuE5d2QFVS0NBtSh7mt+0VXLdPITmi5J8P47x7ngX1tf1Tlam1Pda73rt8PExR3wU91yhG mpBxHwaS2944mHAaErzIJ1vuWIQltJrfuAJth6BcsVLH84ODKzI6Tqw36WrazM0G85GbAvJzpb+ RKwCCGn4aQjY1SmXyNEw9XnE5mmC7TX6iD1nt6+osQJrSs3car6kEqkwhhAPWQkd2kZoQIn9bgT Co9xX8rYYznpU715mSPXpY1FgRhJgioJH0WUVh4GbasoyKcqWNQplm9SAKfQqD5vngrqfFSe3fm 0CdJGE97KP+9l74F5nUTB06EYh/3tnpf479L88LeeQUpQjxFqsGoDD6GfV3Qmvk+SqFncTV5LJo 7BobCjwgBEjcwqeHNK3VXkxkEedhrYEjwOVWT0N3qJdPpHBeVKytO+e31lJFVDGLShZbYiya58z Tma8ut7loh/ywTA== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B Only part of the __scm_smc_call() function uses 'mempool' variable, so narrow the scope to make it more readable. Reviewed-by: Bartosz Golaszewski Signed-off-by: Krzysztof Kozlowski --- drivers/firmware/qcom/qcom_scm-smc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 3f10b23ec941b558e1d91761011776bb5c9d11b5..574930729ddd72d98013770da97cc018a52554ff 100644 --- a/drivers/firmware/qcom/qcom_scm-smc.c +++ b/drivers/firmware/qcom/qcom_scm-smc.c @@ -152,7 +152,6 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, enum qcom_scm_convention qcom_convention, struct qcom_scm_res *res, bool atomic) { - struct qcom_tzmem_pool *mempool = qcom_scm_get_tzmem_pool(); int arglen = desc->arginfo & 0xf; int i, ret; void *args_virt __free(qcom_tzmem) = NULL; @@ -173,6 +172,8 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i]; if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) { + struct qcom_tzmem_pool *mempool = qcom_scm_get_tzmem_pool(); + if (!mempool) return -EINVAL;