From nobody Sun Feb 8 11:44:29 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 7E9FA34B183 for ; Fri, 31 Oct 2025 13:08:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761916130; cv=none; b=ViV6/5cY2x5/hONaT7ismBs72PXQLidKp51NdLhUsClu8zsi35QgPUGJS7QsZK1qvkaMmCTQJEsm/JIcl3AWKQZxutl3ShFXroY4W68/taRTykDGRNd2SA1BNEvsW+IYA1aJW+v23fJvE1bSjfS3lrF+U/6axj+qPcLu09RzUb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761916130; c=relaxed/simple; bh=ZQib5/2OIcg170vq6islUB2C6zYKAesFa9FfnPagCaw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZzYq1C27ShvTSzwVWKNvUGnXtsLJsFqZ5qtIxEIGKrD1v846wKcm4dJ7v7WPRm3PM/rAE3Baev/8ColiEQOBwMGXZcPoDWKANNInT5SvypHFd+bePSbFHA7VwB4M5hq8Th37xKq3f445s19X/+Xern6U9Dg8JSM3Xv1CG5gcQ7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lH+yK8mH; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lH+yK8mH" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-475dbc3c9efso14227015e9.0 for ; Fri, 31 Oct 2025 06:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761916127; x=1762520927; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ccJbH/4yvf5LooWJONtpx85HNAeF1FVpVodVplgG0co=; b=lH+yK8mHDeN8Lnxa2SRF2CPPMQ72Hr5Z2zIskJzy+lRC9sDwE5FvV5pnsPl/SZyKUN GNYIYuuzn7PD/CCufD/inl61u8MCBKsljTxSqjdxKYfszVEG2xldQIdz3xAkWgfsz6MZ K+P/lSk0d6nstDzeO/88iS2rBMvMaQD+XJLf2WwnNd+r97wGuRUgE7dAwe6OhSogKPUR QFVYnxrOGTn9gWJwLm8BG6FWQzAKHaz5hfFAJFKdQqaSk4xk3IrrRn7YfF+YagH/TD1J 0n4FsbHQpmHaGac+mkRRnCSqx1dYLETpY2gwIchTMq+qzUAGznLBC0f/aAWm7fStjEQ5 QJrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761916127; x=1762520927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ccJbH/4yvf5LooWJONtpx85HNAeF1FVpVodVplgG0co=; b=Q6xfQzs9OnjfoYzeq0riUaNayVCDEvWD52em32gdZUelmj/1l93o1psY4bhjqpZkSD FeYHBR9RFxw6XXJNDiOVXohqyNpZpozd8X/9dVsngD31s2oLbqZdO0EB0sik9uhEgJdQ 9od7uygrQmKYbWwvOZp89g5W2vaNJtkMx6b7e01G4pEPUpebQlK3sqOodaROyBPvw4pp 61NLs64Sm7N61nmUjnVTMlcLejX48+8JJpw9dSO86G2AgbvwtSgPKbW/v7gV0cd03xrA j2Y8+K5MPk94X9IhMTVEbcqGuudIJ00S3sQZqMWFzVa0Jt+5k2y+94eTdJ88usPwH4bA MfUw== X-Forwarded-Encrypted: i=1; AJvYcCVqS/CjVXmk1ZNeHLk+RkubB/lybbfsJWi/+BpUWQUQUXvuugP6RJ5SwPqLeBD4Vv7b7hhROXhObBO5yx4=@vger.kernel.org X-Gm-Message-State: AOJu0YwJvaeKM1fM0dBf4hHN6jyCFzwAtJ8h9gttrnIOuztLyUzq07qV L1YdYwiwHa1hOoRCz+X2PvIeHi0WJa5GA3HDNpY7EfaMYkxdKe4wUnwY X-Gm-Gg: ASbGncupKnl700O//F0pdY9qmpxl6egG3pInWvruHY/9PE3TH8pcE5auzMIjSZSwFVe +kp/MmcOH39fBtIg1IFFZOILo35owZOZzW1d58YlnJK2J9AIrUugJnDprGcq+zaSrGDrkAYm4cR mAwl8TvJzIKXwF7ymRtEpT9gHHdhKAUEEKaK10i046Qzm0ygDzDt4WAOaMuRIBNNPzVtbJO8Q/L QtuY79VufHOhjUxQqVWl8i1yitFaFNElVW9s4MothP7ghe8CpxLKmKMXOBzIl00XHtuRqZoieXr lckHXueH9qvHqg8ImALy8i+UENQ4QraajlmAu8yU97/2FWeoswzd0zXNv0uGa99wxuqa2ZsBLu7 uH1mIBgG2h2VqAyP8K/2W125XKxsCW0i98JcjxUPW4kvETVNMYPGd/EHdBX/XW1msWW+/v099WW R1NyA6KN5VlUMTZyY7+rw6PA+B6UDTLejRoO+F7Brw X-Google-Smtp-Source: AGHT+IEpqCi0U/FCAxr0qt6blcRF9KKyqDlQ3rl1LSf7EM78bkfX9BWRYm6r2uYHW58AaeO2vgpvHA== X-Received: by 2002:a05:600c:848d:b0:471:12c2:201f with SMTP id 5b1f17b1804b1-477308b5986mr32940345e9.32.1761916126441; Fri, 31 Oct 2025 06:08:46 -0700 (PDT) Received: from Ansuel-XPS24 (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-477289adc18sm98339815e9.6.2025.10.31.06.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Oct 2025 06:08:46 -0700 (PDT) From: Christian Marangi To: Ilia Lin , "Rafael J. Wysocki" , Viresh Kumar , Bjorn Andersson , Konrad Dybcio , Arnd Bergmann , Andy Shevchenko , Christian Marangi , Raag Jadav , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] soc: qcom: smem: better track SMEM uninitialized state Date: Fri, 31 Oct 2025 14:08:33 +0100 Message-ID: <20251031130835.7953-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251031130835.7953-1-ansuelsmth@gmail.com> References: <20251031130835.7953-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is currently a problem where, in the specific case of SMEM not initialized by SBL, any SMEM API wrongly returns PROBE_DEFER communicating wrong info to any user of this API. A better way to handle this would be to track the SMEM state and return a different kind of error than PROBE_DEFER. Rework the __smem handle to always init it to the error pointer -EPROBE_DEFER following what is already done by the SMEM API. If we detect that the SBL didn't initialized SMEM, set the __smem handle to the error pointer -ENODEV. Also rework the SMEM API to handle the __smem handle to be an error pointer and return it appropriately. This way user of the API can react and return a proper error or use fallback way for the failing API. While at it, change the return error when SMEM is not initialized by SBL also to -ENODEV to make it consistent with the __smem handle and use dev_err_probe() helper to return the message. Signed-off-by: Christian Marangi --- drivers/soc/qcom/smem.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 592819701809..5b7626528284 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -353,8 +353,12 @@ static void *cached_entry_to_item(struct smem_private_= entry *e) return p - le32_to_cpu(e->size); } =20 -/* Pointer to the one and only smem handle */ -static struct qcom_smem *__smem; +/* + * Pointer to the one and only smem handle. + * Init to -EPROBE_DEFER to signal SMEM still has to be probed. + * Can be set to -ENODEV if SMEM is not initialized by SBL. + */ +static struct qcom_smem *__smem =3D INIT_ERR_PTR(-EPROBE_DEFER); =20 /* Timeout (ms) for the trylock of remote spinlocks */ #define HWSPINLOCK_TIMEOUT 1000 @@ -508,8 +512,8 @@ int qcom_smem_alloc(unsigned host, unsigned item, size_= t size) unsigned long flags; int ret; =20 - if (!__smem) - return -EPROBE_DEFER; + if (IS_ERR(__smem)) + return PTR_ERR(__smem); =20 if (item < SMEM_ITEM_LAST_FIXED) { dev_err(__smem->dev, @@ -685,10 +689,10 @@ static void *qcom_smem_get_private(struct qcom_smem *= smem, void *qcom_smem_get(unsigned host, unsigned item, size_t *size) { struct smem_partition *part; - void *ptr =3D ERR_PTR(-EPROBE_DEFER); + void *ptr; =20 - if (!__smem) - return ptr; + if (IS_ERR(__smem)) + return __smem; =20 if (WARN_ON(item >=3D __smem->item_count)) return ERR_PTR(-EINVAL); @@ -723,8 +727,8 @@ int qcom_smem_get_free_space(unsigned host) struct smem_header *header; unsigned ret; =20 - if (!__smem) - return -EPROBE_DEFER; + if (IS_ERR(__smem)) + return PTR_ERR(__smem); =20 if (host < SMEM_HOST_COUNT && __smem->partitions[host].virt_base) { part =3D &__smem->partitions[host]; @@ -1181,8 +1185,8 @@ static int qcom_smem_probe(struct platform_device *pd= ev) header =3D smem->regions[0].virt_base; if (le32_to_cpu(header->initialized) !=3D 1 || le32_to_cpu(header->reserved)) { - dev_err(&pdev->dev, "SMEM is not initialized by SBL\n"); - return -EINVAL; + __smem =3D ERR_PTR(-ENODEV); + return dev_err_probe(&pdev->dev, PTR_ERR(__smem), "SMEM is not initializ= ed by SBL\n"); } =20 hwlock_id =3D of_hwspin_lock_get_id(pdev->dev.of_node, 0); --=20 2.51.0