Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp379444lqs; Thu, 13 Jun 2024 12:42:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBWx+ZS1ZOua+/IR7IVHZQ9g1/ZP8ZMivc+dMXy86CGgYndM2hWJ1Z45ay/uJ2aIHOzXzPQbC3RV2G2VWmhQBgXinIAc8jzL5/QDUxhw== X-Google-Smtp-Source: AGHT+IESO4iLr4BrFdsqxOILlrCHbA0jaDJLlZ1tYrH/KhOc9O9a8sU7DHIibsBnndR5ze9gjc3n X-Received: by 2002:ac8:5f8c:0:b0:440:b388:97b4 with SMTP id d75a77b69052e-44216029c21mr16172331cf.12.1718307724883; Thu, 13 Jun 2024 12:42:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718307724; cv=pass; d=google.com; s=arc-20160816; b=uCEUWPgsNGh+hc8h7WK3FCevQCCI689sX351KdMcLo0UV43u46+dVl0RdA7AqRRp1X iAwMxxSR9il9c138OYEtH6a7+dtpcTiXt/qftXh8wSBhrHP5x0kVMDTKdtQ9kljRVLdd 1N/IdDG0yrjFgwBE470f6aDuAjMi/eTdUuW3BVjtjBLNUQ8XkJvtw0jhsvabFOATAL8F 9jQ93Lp/Mj0Gr82SyD7TNw8YqCVrR5iBO/PmtBWl1mhxw6CrvPUyV3To2wzWZ9e5cZI4 p+b2Vkbn5sws5sUjQ4Y8nkOUH36hnm0reZiYNfSh2c7p9+JMvzXVAa/LromHU4IzAqOB Lh0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=/+m1lrhhPSFDYREp82k6eKz9UMyApdW64J7wKvOB+X4=; fh=YRBcN62/6Qjt3Qer99fG54W4PQFw8ormYAPuh/O9P6s=; b=I8V4gAlkWrpuT7aEHYykK2dhGk5NcYitXC2ntCigJOEhjoS0Ad5WTLX13zCqOOG4aZ vb5Gt2OlaXLyPH8qWjH1ccVU3UmxU4fSq4J/U/6uoJUCu4iHyk81aAsL85xW/bbrVnwN 8MaRFpK4ydDW+a69e8Gns2G9r/AJNyIoHPEqsPrtuHAsXw0LkmU71FxvZpluRWYFJWzZ l6IB3zIoLZZoRNFUxxzxrLaJaKEc0fWMrEXu51625e2MnZFuuGX4rEzqETI5RiyVqMhT TF6CszYiieZys6s1wxKJeubzhsm/Fni2Bp9D/0MkK9QiPNPnANiD0GDFji7iBkMcbq7s Q8Xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=H8n2FqwP; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-213941-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213941-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-441ef3bac6bsi21584471cf.155.2024.06.13.12.42.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 12:42:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213941-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=H8n2FqwP; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-213941-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213941-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 88CDE1C24184 for ; Thu, 13 Jun 2024 19:42:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EE1A14C5A1; Thu, 13 Jun 2024 19:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H8n2FqwP" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA435134407 for ; Thu, 13 Jun 2024 19:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718307719; cv=none; b=j3FCeRwlPgUazE7dd5rDsF6IdidLXu02pJoFXlrK3e1UeDy0d9hU/JrGIljfHzoeyvaex61nK5F/aiQHU42GvBCs08kbydLGIGAQ0jFunj//r3mX65Dme3a72zYE85P4avGTkq6bR8iWSizl0QitOAACffixgBxH2JwpfRFnnoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718307719; c=relaxed/simple; bh=XAZMt9N0NCglaqew8dSYutoepiDFHTvY9wdHf9ybtaM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=EHifgB5vT6kN4PIbNnWfz64PFoN3UtabgXUafXDkLtokrzc5XueEyoxXHct1cGCed/DpqG4TJFPBYK9dJmh0ccxONKxAz2issHpEkJGMwZc/rGRtlRu5IrNVXB5ndCRP/9dixR3/c8uaLgNCh3VO40bICw2zcYzEAEI04xgsNOs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=H8n2FqwP; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from Monstersaurus.local (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B82CF4CF; Thu, 13 Jun 2024 21:41:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718307700; bh=XAZMt9N0NCglaqew8dSYutoepiDFHTvY9wdHf9ybtaM=; h=From:To:Cc:Subject:Date:From; b=H8n2FqwPsn9XaUAxAi9ViKjzn9H+1Tkzuk/1K3gSDTwc6yMFsT1158JD9PRUBOYRr Y/dH1FDyJsknVhZrgFl14dWZcxuZdpYGQcs6jm234HLZK05ZeADGcVq+/VgCaJmfLv nsb1V5NLPlAgYYg99kkhmzjrb4ijc+POsIHLxAR4= From: Kieran Bingham To: Umang Jain , Florian Fainelli , linux-rpi-kernel@lists.infradead.org Cc: Kieran Bingham , Broadcom internal kernel review list , Greg Kroah-Hartman , Stefan Wahren , Laurent Pinchart , Dave Stevenson , detule , Dan Carpenter , linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-staging@lists.linux.dev (open list:STAGING SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] staging: vc04_services: vchiq_arm: Fix initialisation check Date: Thu, 13 Jun 2024 20:41:45 +0100 Message-Id: <20240613194150.2915202-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The vchiq_state used to be obtained through an accessor which would validate that the VCHIQ had been initialised correctly with the remote. In commit 42a2f6664e18 ("staging: vc04_services: Move global g_state to vchiq_state") the global state was moved to the vchiq_mgnt structures stored as a vchiq instance specific context. This conversion removed the helpers and instead replaced users of this helper with the assumption that the state is always available and the remote connected. Fix this broken assumption by re-introducing the logic that was lost during the conversion. Fixes: 42a2f6664e18 ("staging: vc04_services: Move global g_state to vchiq_state") Signed-off-by: Kieran Bingham --- .../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 4 ++-- .../staging/vc04_services/interface/vchiq_arm/vchiq_core.h | 5 +++++ .../staging/vc04_services/interface/vchiq_arm/vchiq_dev.c | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index 54467be8c371..67d853f5f2a0 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -804,7 +804,7 @@ int vchiq_initialise(struct vchiq_state *state, struct vchiq_instance **instance * block forever. */ for (i = 0; i < VCHIQ_INIT_RETRIES; i++) { - if (state) + if (vchiq_remote_initialised(state)) break; usleep_range(500, 600); } @@ -1299,7 +1299,7 @@ void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f { int i; - if (!state) + if (!vchiq_remote_initialised(state)) return; /* diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h index 8af209e34fb2..382ec08f6a14 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -413,6 +413,11 @@ struct vchiq_state { struct opaque_platform_state *platform_state; }; +static inline bool vchiq_remote_initialised(const struct vchiq_state *state) +{ + return state->remote && state->remote->initialised; +} + struct bulk_waiter { struct vchiq_bulk *bulk; struct completion event; diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index 3c63347d2d08..8c4830df1070 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -1170,6 +1170,11 @@ static int vchiq_open(struct inode *inode, struct file *file) dev_dbg(state->dev, "arm: vchiq open\n"); + if (!vchiq_remote_initialised(state)) { + dev_err(state->dev, "arm: vchiq has no connection to VideoCore\n"); + return -ENOTCONN; + } + instance = kzalloc(sizeof(*instance), GFP_KERNEL); if (!instance) return -ENOMEM; @@ -1200,7 +1205,7 @@ static int vchiq_release(struct inode *inode, struct file *file) dev_dbg(state->dev, "arm: instance=%p\n", instance); - if (!state) { + if (!vchiq_remote_initialised(state)) { ret = -EPERM; goto out; } -- 2.34.1