From nobody Tue Dec 16 05:40:19 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 B62C42857CF for ; Wed, 7 May 2025 12:44:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746621892; cv=none; b=NaBhAwSTxBZJg8IETHnPaziCNohFtefhdxNSPMjQyvtYKPrx9NO8Dh72xzHQP+fV+tvfqKusKQx7gjZVwmh5OY1VVUT7Rzam5/HDu0IjlwIG7gtqtEbIrP2KL8Ts0WdNf1/JO8UvcNNRNGF9HprpEjJDs+8QfiskOChrdy4VsqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746621892; c=relaxed/simple; bh=FUN5iesvZIB15oVD5+kjdSiETFouMpoSDwpkgdOWONo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ytk6Z5ThQEavtn0cZ5hzUZRzKrTE4lIV0us7F+CCw07RXul15oQWbnnq5QTFSm0Q5mTSGyMqc3eilWTtksL3fnX774R88vJ6C3gZ4x6pVswVfyyPF1lhI5Db/YRwvBfI6jIrvFpM+JXT2IOxlRigPKSmleDwR0Q45otoE32+9xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fRi5X1Uq; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fRi5X1Uq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746621889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DvlamrKvIRy0y8V7iGg6C04u4JBbaSuDm4R9vBWsHHc=; b=fRi5X1Uq0kUy7zO4XG3eoIC/fxrcuYUJmsaGeu3BAkYk1lzKmT+2OsAI+ZKb457YsHaMNp xc9eZe59mg6O52l7x1fntvYwI4E6HMdKWqZiH0I1jqFH5KlbYfrOFRbihXi00T0ECfO65M 2FNljnuayX2bTgRbBdAm3R0DO1V9A/g= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-fzkrCnn8M0qdaWXuzriQIw-1; Wed, 07 May 2025 08:44:44 -0400 X-MC-Unique: fzkrCnn8M0qdaWXuzriQIw-1 X-Mimecast-MFC-AGG-ID: fzkrCnn8M0qdaWXuzriQIw_1746621882 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A5A91955E88; Wed, 7 May 2025 12:44:42 +0000 (UTC) Received: from p16v.luc.cera.cz (unknown [10.44.33.91]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE36119560AB; Wed, 7 May 2025 12:44:36 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Prathosh Satish , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Lee Jones , Andy Shevchenko , Michal Schmidt , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH net-next v7 5/8] mfd: zl3073x: Protect operations requiring multiple register accesses Date: Wed, 7 May 2025 14:43:55 +0200 Message-ID: <20250507124358.48776-6-ivecera@redhat.com> In-Reply-To: <20250507124358.48776-1-ivecera@redhat.com> References: <20250507124358.48776-1-ivecera@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Registers located on page 10 and above are called mailbox-type registers. Each page represents a mailbox and is used to read from and write to configuration of a specific object (DPLL, output, reference or synth). Each mailbox page contains a mask register, which selects an index of the target object to interact with and a semaphore register, which indicates the requested operation. The remaining registers within the page are latch registers, which are populated by the firmware during read operations or by the driver prior to write operations. Operations with these registers requires multiple register reads, writes and polls and all of them need to be done atomically. So add multiop_lock mutex to protect such operations and check the mutex is held by the caller when it's accessing registers from page 10 and above. Signed-off-by: Ivan Vecera --- v5->v6: * no change v4->v5: * dropped mailbox API and replaced by an ability to protect multi-op accesses v3->v4: * completely reworked mailbox access v1->v3: * dropped ZL3073X_MB_OP macro usage --- drivers/mfd/zl3073x-core.c | 14 ++++++++++++++ include/linux/mfd/zl3073x.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/drivers/mfd/zl3073x-core.c b/drivers/mfd/zl3073x-core.c index 079550682510..a12cfc7eb6ff 100644 --- a/drivers/mfd/zl3073x-core.c +++ b/drivers/mfd/zl3073x-core.c @@ -121,6 +121,12 @@ static const struct regmap_config zl3073x_regmap_confi= g =3D { static bool zl3073x_check_reg(struct zl3073x_dev *zldev, unsigned int reg, size_t size) { + /* Check that multiop lock is held when accessing registers + * from page 10 and above. + */ + if (ZL_REG_PAGE(reg) >=3D 10) + lockdep_assert_held(&zldev->multiop_lock); + /* Check the index is in valid range for indexed register */ if (ZL_REG_OFFSET(reg) > ZL_REG_MAX_OFFSET(reg)) { dev_err(zldev->dev, "Index out of range for reg 0x%04lx\n", @@ -557,6 +563,14 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev, FIELD_GET(GENMASK(15, 8), cfg_ver), FIELD_GET(GENMASK(7, 0), cfg_ver)); =20 + /* Initialize mutex for operations where multiple reads, writes + * and/or polls are required to be done atomically. + */ + rc =3D devm_mutex_init(zldev->dev, &zldev->multiop_lock); + if (rc) + return dev_err_probe(zldev->dev, rc, + "Failed to initialize mutex\n"); + /* Register the device as devlink device */ devlink =3D priv_to_devlink(zldev); devlink_register(devlink); diff --git a/include/linux/mfd/zl3073x.h b/include/linux/mfd/zl3073x.h index 8df10b82e3c2..a42a275577c4 100644 --- a/include/linux/mfd/zl3073x.h +++ b/include/linux/mfd/zl3073x.h @@ -3,6 +3,7 @@ #ifndef __LINUX_MFD_ZL3073X_H #define __LINUX_MFD_ZL3073X_H =20 +#include #include =20 struct device; @@ -12,10 +13,12 @@ struct regmap; * struct zl3073x_dev - zl3073x device * @dev: pointer to device * @regmap: regmap to access device registers + * @multiop_lock: to serialize multiple register operations */ struct zl3073x_dev { struct device *dev; struct regmap *regmap; + struct mutex multiop_lock; }; =20 /********************** --=20 2.49.0