From patchwork Mon Dec 9 11:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899409 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 EE800216E29 for ; Mon, 9 Dec 2024 11:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745387; cv=none; b=f6j2skYNvLDzB1aCfj5pY4vFHbFCjrcCAdsnyJWCP09j6lyRncnjN2cA5U3dcqZXJUJz07Uci+DMAN1yzy+CNIBuYJeIugsazvFNanaGRARSL+uTiBf2EVSTOSRE8VvDln7Kb0OPR+xyfbgb5lqyShMchnZ3JDU7vqLkrRExbW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745387; c=relaxed/simple; bh=0LO2zPYAqi4rqcBhiJ1BLvPKoKw9ftNC08/t+0RUAyY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VgLWrVrbbjQvly5cehyurokOON7idEZw40BoI42pswocEeFzFN5k2WW6+xrSKE2KO8mcP1cYKkpli0Y+ca5JX8BNOzJ9IfkuLCLSkXQ3KytQqIAepPIH1Q8+ZaYpYzHQCMkNUg2fY78iQRKakGBwKkw28A9g0++Rcq9Vb5RrL8s= 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=X6JsH1GL; arc=none smtp.client-ip=209.85.208.41 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="X6JsH1GL" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5d3cd8e59fdso277747a12.3 for ; Mon, 09 Dec 2024 03:56:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745384; x=1734350184; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Useh55TM0tjeQrnlgj6s0Ix5hvl08p6sYbXbXf2KJKQ=; b=X6JsH1GLHuoe6kfgGxVKIvfazeDh8iOL85QGHntNsMaBLMUmxlgyTpfb4mBQee9OUK JfO2SL7OxbgJDCbj5RwzwcfkJbwZjW/rNjO7fj7YNqfNBzwEy95ucNsPiDBCfdkgQq8H B2rEnuByrFrlaBqZRp+lJpl+FQEXp4Q4VGHIuYH5kgCrVszfHl980j69SNaVaxcQ4iO9 P/lwNGSNuIEzAGR2SeSwmSNQHEdkqPjsqcmH8uIVJ3Rd3ZTRjTwdZGmpAN7oPjd6fFiO DbmIEL61/1AqKEUvXrr4075OWj/uFYvQXXk5EhJdNPhwcyVmRmG9LVTsfo0wpjNKiUZa gWrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745384; x=1734350184; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Useh55TM0tjeQrnlgj6s0Ix5hvl08p6sYbXbXf2KJKQ=; b=WFZml5ZTFGlRqZohgGe6W+CkULfhBJmQ41hk4y4jtP6jGk0kVYuV2AlU1GhuoxvYdW mHaqwZXxVicCJAAAfObcHeQlx5pFfhE9Q0kuncnTI6wWRk644Khdxi3D35AIleMqfCAQ jImRGwEnqKO1YVjo4lppDQQq2KuZo6CpUDp915AXoUGx2UIoMursG5obh9LOdZwPOIj8 5OqPjleWixRJHUhN1fG2Ab8JqNCDQ0C/Y6Cd4+9rsqtMXP6hjqgP9upeblnhKIwX0D6H LS48FWbMKsEnxG9WN+getxd0fPjqoOpmmUqmgnfV7DDnc4rIUEYwiZqrsUDUdisFheeS p4Hw== X-Forwarded-Encrypted: i=1; AJvYcCXdAvSPUBC/GNBu+evRW286KMSHujv6Ft92OQAyxKi7RodEzo5XJHNd5KccRmjgYEb7xYXO32NZbfLcbG08@vger.kernel.org X-Gm-Message-State: AOJu0Yxoha6qercZIp17SS+hbqt6mVKdcvv1fRz9KrrvyHqs0WSWQbt0 4WUb0HWl94Chm9Myh5SD2RyjiglyD3BZT8tFU4REBnr8+5zClVc0dg5SUAOPEBQ= X-Gm-Gg: ASbGncv2UCF/uaJBt3F7ndoUC7Kt0+s6Jw8fn22INjiZEbRQiQXwj4KWP35GbiJpy60 bUBP5uH+mj4iMj3rSeazuJVRRulsfbLkDZf8uLQr3BjVRq/30lWEnqLz35LuIhYr2HVarKZeETm 8fWhWDbtgGZW4+f+rJd8cGunOt5iK78ueMjunC0FKzxr7/KKgIMhA4yF1es0SXzcIFX8wi0vm6J yzhT4TzbnqYyijt/d9EmqIjuHYSyhqqoCZEv8H+fL8pOltV10ARuCGTr7zNAxey X-Google-Smtp-Source: AGHT+IFy0QEwd71L8F3WWzjmNnwcpld/A/VFpC2mWyELkqnYLuwFzGiop941yEx4OjXTcWiq0BYq5g== X-Received: by 2002:a17:907:7d8c:b0:aa6:9b81:e7aa with SMTP id a640c23a62f3a-aa69b81e971mr17438066b.7.1733745384224; Mon, 09 Dec 2024 03:56:24 -0800 (PST) Received: from krzk-bin.. ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6651c01c5sm343333766b.23.2024.12.09.03.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 03:56:23 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Neil Armstrong , Andy Gross , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v3 1/4] soc: qcom: pmic_glink: fix scope of __pmic_glink_lock in pmic_glink_rpmsg_probe() Date: Mon, 9 Dec 2024 12:56:10 +0100 Message-ID: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 File-scope "__pmic_glink_lock" mutex protects the file-scope "__pmic_glink", thus reference to it should be obtained under the lock, just like pmic_glink_rpmsg_remove() is doing. Otherwise we have a race during if PMIC GLINK device removal: the pmic_glink_rpmsg_probe() function could store local reference before mutex in driver removal is acquired. Fixes: 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver") Cc: Signed-off-by: Krzysztof Kozlowski --- Changes in v3: 1. None Changes in v2: 1. None --- drivers/soc/qcom/pmic_glink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c index caf3f63d940e..11e88053cc11 100644 --- a/drivers/soc/qcom/pmic_glink.c +++ b/drivers/soc/qcom/pmic_glink.c @@ -236,10 +236,11 @@ static void pmic_glink_pdr_callback(int state, char *svc_path, void *priv) static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev) { - struct pmic_glink *pg = __pmic_glink; + struct pmic_glink *pg; int ret = 0; mutex_lock(&__pmic_glink_lock); + pg = __pmic_glink; if (!pg) { ret = dev_err_probe(&rpdev->dev, -ENODEV, "no pmic_glink device to attach to\n"); goto out_unlock; From patchwork Mon Dec 9 11:56:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899410 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 5DC9622069F for ; Mon, 9 Dec 2024 11:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745389; cv=none; b=uLmV+UmzJjr1x7X7bFN0DcwouFpLAQMGa4dt/epzNqwRH+0Wts4jLLbtGRXk6iqHca5dw9XclukrcxFNWmiolFnq+YUwLJVIacN8Rm9USISu7DBM3Lm44ZVUWs9cgZF6yHs0bFapyUbtmWXwccqFTW+qZCYhbJE2X042RwZr9Jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745389; c=relaxed/simple; bh=UYoZ37RyjculWpGQiCFSZYiIahzyfcf1uiQSJqQ8/ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F1aO57KgmiQyO5nwmpHsd67Gdim4M0SOeKw05sdyeXv7ziISjTF6gubUBgnVIzlRPH9Yjhz/ka1D9msP85rLobnmkvBSFu59R9ZE2I92C395Gt8fgmC9IjWkZI2v7qnqtO0/niXiyK60sKIkqOLsV5GhTzQ9D8DdOMVYXDw5ou4= 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=jldf+6SX; arc=none smtp.client-ip=209.85.218.53 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="jldf+6SX" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-aa65f707419so40362066b.2 for ; Mon, 09 Dec 2024 03:56:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745386; x=1734350186; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hn1iITUqCTWw5geBpowIVLe7vef2f6kBTXYqRCfLbA0=; b=jldf+6SXzkNxO5eR3FCMfMXk3TTrrbFryRvlxyefDC7+Iwip4K7LQPakSquKhcKnFL lbr97RAcmoHMlmUyuVYB8wTpeyTxEd3FNfWzSviBxo7kr+lQKy3/P02GyPhB3gO7ce2p 5jqTWKk8to0zr5qzfCr5416wlMDlleqtVsD+qZGN8eRmqLv1R/wNg+4hgjawG8TtWXMY Wq9kkJ1M7Tgsn8mNPanOXDMZCfrwzyQ5Pqcj2iot29w63epl1aVyZq5zECCk48fg2K4f DdEH2+O9BD9IEd0fzegfKcPMH4PJo0eQeMO7aNsK2/VAzdnLXKc02dKewZNOyeRifXA6 1aYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745386; x=1734350186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hn1iITUqCTWw5geBpowIVLe7vef2f6kBTXYqRCfLbA0=; b=bYUyKQP8JiXg2JZW9DeFfnhd+Wuf/b6MKbuvOZ07hHUatv8kQzViBvVolAFvgSpY2s /EVWWiuy9L9f2mrZWA1eQCjLd4b9IDEZ9F/8nZ0xpaefwXD86f+J2CFkxer/RIk5bSLT BaRd99m+b0mFrh21Cob5ZdFrxfgJeQWACcSWzhWbiwq5+kRIbRp4SLaKVYx7a/Rd4nyk 6eC/2hrqnnm2VEL0ARStr2FV18ID3SqgsZt0tAm1fVTu5F54/SLsK79PNEUorh6pSP1p CAq4kPY6hGggK/gOmO9WaB40oGuoUavNHK7+QUzqsOoAwa7pxRHaP20L9jCNP9UQkNpQ CUcg== X-Forwarded-Encrypted: i=1; AJvYcCVvjri7I2/vvRvSE/LzjDdCpJWp5/aKNUZGIBE4JKu3SMbrv1ns+GkRb2Ek5wwkfCF6U6dbQzj4d267TVE9@vger.kernel.org X-Gm-Message-State: AOJu0Yysdb95imgnftvpoaCLZm1zFs00Kzo6vGoIjSd+Su1gkUgKVBsp gihkASO/ItaxK8LToN0c0XE2DEQMSS68CVWoHPpwNDS5OsG0kCD3MdrYNHOWE5U= X-Gm-Gg: ASbGncurDy0pnjUKRquISKYFr/o1fm00ga/L+j4hGq2x9PfuFXF/R8+6XBOt1xjEDPq mHZ0G+qb0D+0WZ1d7QckgESE7cQBiK8EZdnX1phcUtcThVD2gWa6pQyatHYnkthSD0ePHikWEzq fnpyfAlrcu3cJFAzxJIRLHCAynEbuiA/ZNk2pwMJtOYeqcYltGZ3Oyen2VeAuAVWyvtXmuVojHG LIg9+Ncb0PtQrXO9RcVeh6MfnHExm0GQQHbbm05zgmTNiAN2k01Uz//g2YTcikF X-Google-Smtp-Source: AGHT+IH6FhBYyaKwHnnukYERgUgguK/+8BJ07//maa179WbVCtwvOKPm8MChdcKGphqtryASdBJurg== X-Received: by 2002:a17:907:944d:b0:aa6:3736:bad4 with SMTP id a640c23a62f3a-aa639bd5e31mr533078466b.0.1733745385627; Mon, 09 Dec 2024 03:56:25 -0800 (PST) Received: from krzk-bin.. ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6651c01c5sm343333766b.23.2024.12.09.03.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 03:56:25 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Neil Armstrong , Andy Gross , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH v3 2/4] soc: qcom: pmic_glink: simplify locking with guard() Date: Mon, 9 Dec 2024 12:56:11 +0100 Message-ID: <20241209115613.83675-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> References: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify error handling over locks with guard(). In few places this elimiates error gotos and local variables. Switch to guard() everywhere (except when jumps would go over scoped guard) for consistency, even if it does not bring benefit in such places. Signed-off-by: Krzysztof Kozlowski --- The part in pmic_glink_rpmsg_probe() depends on previous fix. Changes in v3: 1. Rebase - bigger changes in pmic_glink_send() comparing to v2. Changes in v2: 1. Do not use guard() in pmic_glink_probe() because of jump. --- drivers/soc/qcom/pmic_glink.c | 51 ++++++++++++----------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c index 11e88053cc11..f842ffa3c356 100644 --- a/drivers/soc/qcom/pmic_glink.c +++ b/drivers/soc/qcom/pmic_glink.c @@ -4,6 +4,7 @@ * Copyright (c) 2022, Linaro Ltd */ #include +#include #include #include #include @@ -100,15 +101,13 @@ void pmic_glink_client_register(struct pmic_glink_client *client) struct pmic_glink *pg = client->pg; unsigned long flags; - mutex_lock(&pg->state_lock); + guard(mutex)(&pg->state_lock); spin_lock_irqsave(&pg->client_lock, flags); list_add(&client->node, &pg->clients); client->pdr_notify(client->priv, pg->client_state); spin_unlock_irqrestore(&pg->client_lock, flags); - mutex_unlock(&pg->state_lock); - } EXPORT_SYMBOL_GPL(pmic_glink_client_register); @@ -119,28 +118,23 @@ int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len) unsigned long start; int ret; - mutex_lock(&pg->state_lock); + guard(mutex)(&pg->state_lock); if (!pg->ept) { - ret = -ECONNRESET; + return -ECONNRESET; } else { start = jiffies; for (;;) { ret = rpmsg_send(pg->ept, data, len); if (ret != -EAGAIN) - break; + return ret; - if (timeout_reached) { - ret = -ETIMEDOUT; - break; - } + if (timeout_reached) + return -ETIMEDOUT; usleep_range(1000, 5000); timeout_reached = time_after(jiffies, start + PMIC_GLINK_SEND_TIMEOUT); } } - mutex_unlock(&pg->state_lock); - - return ret; } EXPORT_SYMBOL_GPL(pmic_glink_send); @@ -227,52 +221,42 @@ static void pmic_glink_pdr_callback(int state, char *svc_path, void *priv) { struct pmic_glink *pg = priv; - mutex_lock(&pg->state_lock); + guard(mutex)(&pg->state_lock); pg->pdr_state = state; pmic_glink_state_notify_clients(pg); - mutex_unlock(&pg->state_lock); } static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev) { struct pmic_glink *pg; - int ret = 0; - mutex_lock(&__pmic_glink_lock); + guard(mutex)(&__pmic_glink_lock); pg = __pmic_glink; - if (!pg) { - ret = dev_err_probe(&rpdev->dev, -ENODEV, "no pmic_glink device to attach to\n"); - goto out_unlock; - } + if (!pg) + return dev_err_probe(&rpdev->dev, -ENODEV, "no pmic_glink device to attach to\n"); dev_set_drvdata(&rpdev->dev, pg); - mutex_lock(&pg->state_lock); + guard(mutex)(&pg->state_lock); pg->ept = rpdev->ept; pmic_glink_state_notify_clients(pg); - mutex_unlock(&pg->state_lock); -out_unlock: - mutex_unlock(&__pmic_glink_lock); - return ret; + return 0; } static void pmic_glink_rpmsg_remove(struct rpmsg_device *rpdev) { struct pmic_glink *pg; - mutex_lock(&__pmic_glink_lock); + guard(mutex)(&__pmic_glink_lock); pg = __pmic_glink; if (!pg) - goto out_unlock; + return; - mutex_lock(&pg->state_lock); + guard(mutex)(&pg->state_lock); pg->ept = NULL; pmic_glink_state_notify_clients(pg); - mutex_unlock(&pg->state_lock); -out_unlock: - mutex_unlock(&__pmic_glink_lock); } static const struct rpmsg_device_id pmic_glink_rpmsg_id_match[] = { @@ -379,9 +363,8 @@ static void pmic_glink_remove(struct platform_device *pdev) if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) pmic_glink_del_aux_device(pg, &pg->ucsi_aux); - mutex_lock(&__pmic_glink_lock); + guard(mutex)(&__pmic_glink_lock); __pmic_glink = NULL; - mutex_unlock(&__pmic_glink_lock); } static const unsigned long pmic_glink_sc8280xp_client_mask = BIT(PMIC_GLINK_CLIENT_BATT) | From patchwork Mon Dec 9 11:56:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899412 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 4D46E2236E7 for ; Mon, 9 Dec 2024 11:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745392; cv=none; b=mtgDKB7eCDsDlcqkxHzaz4qgm0AHNb4gnxS4fq1b4soHE7p8KkOezELJj5e34gsKOn8EcHPhXNpMp2HEKz1Lcn9Zgz9Lpfm3HbSiJHFsPQT4bkkSXrKG2l8Gh52EkSHswWwU3HhVi7nHkc0iAiD6GJsmxEJyauLwmxojQwILOb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745392; c=relaxed/simple; bh=njRJMFS53oVLlFPOfYmEgfNE0jHwMkDusGCNOuUeDQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UloTsBv0G987AymiqGsAc3CFkT2ebzV3TVmCzvIJEFiMxR21R0m+t/J77HNuFmvRs3mtbek/6y6k6uq/Wc7qer1cthvNzjO3GbM/Ydflxhl3L1Eha2JoaZn1RuoNHiC9ChhSwwBfvswM8oDceFeJDhY3OhCGjwItAErwJcRcDDA= 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=j/BQYd1b; arc=none smtp.client-ip=209.85.218.41 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="j/BQYd1b" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-aa62fc2675cso64920066b.1 for ; Mon, 09 Dec 2024 03:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745388; x=1734350188; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dDkrPmX+rnC8j6/Av609kaQIfkDAMEkIyzULcEtJ5go=; b=j/BQYd1bNGzUkFsKBJ97waycncUj6HWilLt2nGPQr9Wp3LE/rBSW1qHpru2HWJoQlO MRqLdiQSGJv7ewJXBGrY+Vnei/L0QJhg/NJTVdrvKtKfO42H7jcyHCwntu3aJhUIl8UY t0qj9Qdmu9+E5A36Lxn1ee0Pauim0RJLtyfeSxmlYODjfher7O6LKzeAoNeftXWAqipG sCky3v+8JHnfUzd6e3nQ9ruQl/zpbIg5R2hazKrLL1o3fmO5r/8mXAyoFizp0zMadLv3 VKUw9LeYn5RJiP27gE9ydGgFq4kRocg80kt1/oWxkSx2MEFDaq20LIuDU9A8cPZw06KE MneA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745388; x=1734350188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dDkrPmX+rnC8j6/Av609kaQIfkDAMEkIyzULcEtJ5go=; b=jYZJxUUvco20y6+UQoKfjlJT/PVvYlTd2tr69p55pLdym6K4veB5b5o5MnLNxUgBbg 3DkCobK0uAXMGXmpSSH1XaaS9J1kPXSFSOG/HHtg1Rm7zUW9FLXA2IjTx65pkKSPEGbJ 1n6AR5NhEof+HYvwBFD4l2+6D8+wgQvreCjkNp6ECgvfEOitk6E4kS9lce5MHPSUKs31 xnBzDYHmzoOP1fa8kgt5Djow7C4fYoBF7ia5nuex5EmUonpEINOQXuvFk6Y6sUdKxVUe doILV3y3a1IOXMjHt+wTSnbASV8L2PCW+Strx1TSdacobt2fdu29+QoNWqqjRvKTbN+K KgLA== X-Forwarded-Encrypted: i=1; AJvYcCX53oGGW8ikM/CHcAeqOQAqost9BBGhHkSE8xlMrVZlYzmunC8UKqq3aFmUhj6J+rTQ0m/r3/W3vc87q5K/@vger.kernel.org X-Gm-Message-State: AOJu0YzlXBUWGuY8BY3JXDNoOaXss8iVKU8fMKwQnt8riRlCMAmR8Kyu XySS9ARM9GVsRr2CodaYvQTU1Ziq7G10E+vxknP2kXpBrKtZr7al9Y6RXiMuZkQ= X-Gm-Gg: ASbGncuwQ9/K3B3osfs8bih540CcbPyuRgVxg5HwrjUqBoDYbECXYO3oxOyTGgTghKY nOzVGnVTjsKWgGUII3q4vLB4Sd2XvcoKrnYt72cKymCb8zGCN5bfEn6LtHGJ5sDjkQZDQiWmMbL Nc9O6oaYL5wcxM5uSXnqLPYkPm8wj7w+JkdEMOTWh+2jGeyClNH+sOk4Mp2zCFjwGjOS/0Ef1b6 w6ol905K87UcFweTwuHWs5HNiKuhtu5UV1AyywWdtUZK313i5+3VzJFwguOn/Oy X-Google-Smtp-Source: AGHT+IGaZyqKQzZD247wMomlUwBJH4NbdZftbTBnrY74rFdm2bKBbV7DjbALRQ98dOG8bxWswacXHw== X-Received: by 2002:a17:907:3f1d:b0:aa6:2572:563a with SMTP id a640c23a62f3a-aa63a10f275mr510577066b.6.1733745387038; Mon, 09 Dec 2024 03:56:27 -0800 (PST) Received: from krzk-bin.. ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6651c01c5sm343333766b.23.2024.12.09.03.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 03:56:26 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Neil Armstrong , Andy Gross , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org, Dmitry Baryshkov Subject: [PATCH v3 3/4] soc: qcom: smem_state: fix missing of_node_put in error path Date: Mon, 9 Dec 2024 12:56:12 +0100 Message-ID: <20241209115613.83675-3-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> References: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If of_parse_phandle_with_args() succeeds, the OF node reference should be dropped, regardless of number of phandle arguments. Cc: stable@vger.kernel.org Fixes: 9460ae2ff308 ("soc: qcom: Introduce common SMEM state machine code") Reviewed-by: Dmitry Baryshkov Signed-off-by: Krzysztof Kozlowski --- Changes in v3: 1. Add Rb tag, combine from other series. I don't quite get why rest of other series was applied, but not this fix. https://lore.kernel.org/all/20240822164853.231087-1-krzysztof.kozlowski@linaro.org/ --- drivers/soc/qcom/smem_state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/smem_state.c b/drivers/soc/qcom/smem_state.c index d9bfac6c54fb..cc5be8019b6a 100644 --- a/drivers/soc/qcom/smem_state.c +++ b/drivers/soc/qcom/smem_state.c @@ -112,7 +112,8 @@ struct qcom_smem_state *qcom_smem_state_get(struct device *dev, if (args.args_count != 1) { dev_err(dev, "invalid #qcom,smem-state-cells\n"); - return ERR_PTR(-EINVAL); + state = ERR_PTR(-EINVAL); + goto put; } state = of_node_to_state(args.np); From patchwork Mon Dec 9 11:56:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13899411 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 3BB7A222587 for ; Mon, 9 Dec 2024 11:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745391; cv=none; b=jFpCINCZPJsCw32ML51qjOx7VQzPKIbPoj721ReHv2S/xd7avbW6BXuzb9qwIONyh/CpOrbSWCwa1pw4t4TJdfy64aVUk+XGQZW/0+wlcmFLnCtlMkltMhO5ZTiam6ARSlFEUJAyt3ZN0eEOgupmHR0CiDMSePlZttmduGLFGsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733745391; c=relaxed/simple; bh=ysL6WTjrVc7FAA8tQN5UDR36z9EBcMk7yq8nQKkF4tY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eNb1xQiuGGcHsjUPqTCBBwrpIetyifWbAUhx67PQvnjiuN/VnqEwsesWxP6jR4Mypx93ygAJq4GH2TCfv4Dap66AgjyvJxIw1SOMA3qiH7AB9t4Yt0xpKQ8aVMrdAROvABEUTg9X6al1u1g4OtmqYbmkX67vL24AFJ80Icy5GFk= 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=Ml5HkllS; arc=none smtp.client-ip=209.85.208.48 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="Ml5HkllS" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5d3ce64e7e5so305159a12.0 for ; Mon, 09 Dec 2024 03:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733745389; x=1734350189; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o8AVtYyZc/IWaDoxx47aL1vyovDYySo46TxvDoofEG0=; b=Ml5HkllSsKML3UxIRbTk4t0xHlRkRt13oMa0SYnOCcdDcNEw48N6rKOGaGBmESGfl2 MXwk0RznV+JG3tp0J0ExxBG4OEHbYXMkIw6lFSAtF9QBNpAms4ss6G2GHOYo+QEvWWdN vFFMZ+vgX0+5yKONr9P+ATEA5cLnUJiimvqeo0TWko4l34sO1I89bDelrbM7/4p2yZ2a Dvggz71W/2I2PA5FMfiXcTVtr2BCnGnEn2Rbpm9q9prSOE7TgHZup66xIQxCiIptk2rl m0N+hd96yyEaVzyWm+js7NkTo2NdZ2Sbs7a8Zrt25IdGWykNwHmgEmV/zkVjhRNUL8tm fj9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733745389; x=1734350189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o8AVtYyZc/IWaDoxx47aL1vyovDYySo46TxvDoofEG0=; b=fL7Q4MqKAX+BjY6nipSdR1hG6sAlLl6iT7C3vR4OhOZPANqzhhxms3jxp9aOK25KpS LjZ+WX+u/0/qYezHu/FN5g8XyZO/0LCrd/Z1xiBab07g2CfpsfdcEPMfLc9ayHNiiEZ8 gcVj91G8XodiS5+/5m3zV8oS9Uss9vkcUbY1gn0DMxRBHmKfFGdSlaJbSjojM6FiLLqG VTkvayokls51lwJI+0MtPWrEm2PZaq5iplfQcB30sQUGRH5QyOWFo6cPViB/ZVsBPcuQ 0vW5PRByTFp7GECiI8e51hGSw8PFWB5LIa83IGmZffORda34UbPbyStyV0Epu/96BDzD oxxA== X-Forwarded-Encrypted: i=1; AJvYcCU9g0zfCOrl0yBWkg2uU8MJg0wmXjbazuzQt8bli2hFSol5N0PTd16HEeIsb1cdk1Az5b2Mf0P0fWjC98RC@vger.kernel.org X-Gm-Message-State: AOJu0YwVdK1OWY9+OBq4x2dNBIyYXfk5ttImKPZ+C1Iby4oQfOruTW2F A1cdkc97xosUeMNGIAu2CmlHvX9l0lrl9NHlVhr4soEBto6F8eL1vVmTeyiOMyvCA4lFNNPbltC S X-Gm-Gg: ASbGnctvmMMzsCYXMuy5fksMiJJwQyr83qBXRkYP4pbd6RYt1dfyIM/Fgn7lCluGwAK wFS/q5++hRBHj76dolhvXkwU4adLkY+Gy11AUnXyoGIEX3Oa9sII2g5qDTUIP/EpfkGBUlLTgq2 0m79wJNwu8ZhW/D4H42cWkRWqgcBcIXogWROD1oXy0nGyRt5LZn0qR9auBLAWpNy31XgyZpcrFd f9f15Bk/XFNbqFdZVCv3MbOf2jaHdLzix5va8aAv1OFFaIQVZbauSLFLBO4PteV X-Google-Smtp-Source: AGHT+IFbt50n/X6rA/A5IzwmfbG39lpIfZK4JXG7TIUfY7QQd4Ox9JNG3Mk49+rANy/9rD2YAGFw6w== X-Received: by 2002:a17:907:2d27:b0:aa6:2d35:243b with SMTP id a640c23a62f3a-aa63a025088mr531709466b.3.1733745388194; Mon, 09 Dec 2024 03:56:28 -0800 (PST) Received: from krzk-bin.. ([178.197.223.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6651c01c5sm343333766b.23.2024.12.09.03.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 03:56:27 -0800 (PST) From: Krzysztof Kozlowski To: Bjorn Andersson , Konrad Dybcio , Neil Armstrong , Andy Gross , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH v3 4/4] soc: qcom: pmic_glink_altmode: simplify locking with guard() Date: Mon, 9 Dec 2024 12:56:13 +0100 Message-ID: <20241209115613.83675-4-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> References: <20241209115613.83675-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify error handling (less gotos) over locks with guard(). Signed-off-by: Krzysztof Kozlowski --- Changes in v3: 1. None, previously here: https://lore.kernel.org/all/20240822164853.231087-1-krzysztof.kozlowski@linaro.org/ --- drivers/soc/qcom/pmic_glink_altmode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c index 463b1c528831..bd06ce161804 100644 --- a/drivers/soc/qcom/pmic_glink_altmode.c +++ b/drivers/soc/qcom/pmic_glink_altmode.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include #include @@ -114,7 +115,7 @@ static int pmic_glink_altmode_request(struct pmic_glink_altmode *altmode, u32 cm * The USBC_CMD_WRITE_REQ ack doesn't identify the request, so wait for * one ack at a time. */ - mutex_lock(&altmode->lock); + guard(mutex)(&altmode->lock); req.hdr.owner = cpu_to_le32(altmode->owner_id); req.hdr.type = cpu_to_le32(PMIC_GLINK_REQ_RESP); @@ -125,18 +126,16 @@ static int pmic_glink_altmode_request(struct pmic_glink_altmode *altmode, u32 cm ret = pmic_glink_send(altmode->client, &req, sizeof(req)); if (ret) { dev_err(altmode->dev, "failed to send altmode request: %#x (%d)\n", cmd, ret); - goto out_unlock; + return ret; } left = wait_for_completion_timeout(&altmode->pan_ack, 5 * HZ); if (!left) { dev_err(altmode->dev, "timeout waiting for altmode request ack for: %#x\n", cmd); - ret = -ETIMEDOUT; + return -ETIMEDOUT; } -out_unlock: - mutex_unlock(&altmode->lock); - return ret; + return 0; } static void pmic_glink_altmode_enable_dp(struct pmic_glink_altmode *altmode,