From patchwork Fri Feb 28 15:17:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869960 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 3D8621EF36F; Fri, 28 Feb 2025 15:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755861; cv=none; b=rnL7oUNDMNs9tymf7GhiUzgQYgVwiO9CGoiAslQaOMNQDKGpXK5d/fbVbjwE7yo7qaELBFEtKCH2VtCe5qDbwfyEfKjB0oYC1pEygWLBkrX+GKlKFOZYm2SiZFvhO7HhJLNcAa+CAFQdL7G7AaHAM6/9NtBDVnT8Ai7ftWi353U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755861; c=relaxed/simple; bh=js0ULzWgxljakcpWyCSCNziXEbJUjtxNr4WUb1YkhYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BkbX0HLRuVGYJ4bkkw8cULY/eRJ12Ft0zuv7xNzeqvRTvMy748coyiWXiYvqsysDk7zUZNp0V9/wgvkJ52Rqiq01x4bnKJM1n/wiwkQ9lxEcCIgIK9Zd3wUACSxxm4bVnVgtOvKmBCmdF5ygQDoPPnm8uCyFVRdLA7xsu1RBRok= 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=T5aNCX/c; arc=none smtp.client-ip=209.85.221.50 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="T5aNCX/c" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-38a8b17d7a7so1389619f8f.2; Fri, 28 Feb 2025 07:17:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755857; x=1741360657; 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=2J7Ov3Q3zvbb4Wq/N681pfQJSfPu/xmR7tlaT0hDhM8=; b=T5aNCX/cjwPQhyptdhhDzyHrbU7Myqlxn8Y1d5lquXkXncXZrBuApaf57uJw9fzjPk yEEt1Who9iywvjwLDwzoDAVRzTKhw12ogXbyNwtH5PExKKd/nTSF6ff4cAsR6HM7x0KC 4YwQD7Nb6OC9nQu9D/DNRxNw0+3KCLIxFy05QMPXGbPxf/EyXtgdIRMAoFui7pICygpE mfQjbepus4zUQIZY9DsrPKQbfIAUE3Lh6fsWbV6+V6aeRHd8Ec85cah0akrmFOMZYJOV WH/c+vVWMaoI0MuY6fR4HofKyzBczriWSL3+57n+57MMPoBIv+PgIbLdIJUoCp60chQB TPAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755857; x=1741360657; 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=2J7Ov3Q3zvbb4Wq/N681pfQJSfPu/xmR7tlaT0hDhM8=; b=jgnULtvVnAkmuBEqpFIIX3rvq6I04mnVU8L31n9NKvk8+KnvIBiGN691nOkf5KRC17 ajLc2IAFk7S1tXkb4BPvtT6cU9ICUY8oMijlEYn9xQMJXPLQ59LlGQWW6JYUfoYYHZUa rLUTtJVcTHmf2OzLnON+pyMggrh3EdZdTX+RurtjAVFWruQC5nB9TdJkAUPhNjWGg7TF 161Z8zN7OdG98lLpaWITXln1WHgxFQzUzzgSDggu3+hbu8uBki7lshMbekM7C5mBvUtj 33A1+SIvg8zlbl3CgXvBQG7eaXOvNcKdA1Cj9ocToV7CYYtm5OfMti+nlU+MG0Bwko8m l/9A== X-Forwarded-Encrypted: i=1; AJvYcCUWWmr0giaVEMO/A4BNFhzmP6ug/E9nX+UM5wCz30iRUnRhg6JvNxXuH5lRf9JJy1mv1MxLPOoaAfk=@vger.kernel.org, AJvYcCVESt2WO1GyBsDVfwVy9PicxBsBk7tadwCwIOEPhIxwxTclYFV5SPDd1ZXQxSqI/pLRW8UhxtmFHWsK2m0=@vger.kernel.org, AJvYcCVYKsEoIZCZjsdHcs7/CYK+KCT84VkxZjLDAn65OnWZ/myupT8DYT6/Bp+pHEgfOgoPR9c7/lvuCnKMyYWR@vger.kernel.org X-Gm-Message-State: AOJu0YxmVPDAq42CCN/SQsMRK8U97WB//Yi+ncUUYYdytMlPXRxm3ou3 lKMH3CJhyCZTDG6zq0YhtertX2/mGc+n3wGPb3s4jsSMpHufiHZV X-Gm-Gg: ASbGncuSe2zAeJUPqmeCM6iqmD1qGBY1Hz2iY7Ate6PznO39EHEm8BEdtYwjQb7mBoT usXJitAO61bxxA/5DheZ0MYoDMYMI6zc2DIpcPypVbkZeAUTqfeDpxp3NfGUeqH+aweCB1vBwBw znJGSglVxWx07xgG6YgmJxJUag1Z1/kkcE+KNHZ1Rv6OxMM2oPpL0U255QEyl3/Wmx+k2mC301h LF7pGalMZFQSijvO5TCH5pwCoUYdJ6yn33wvueoOn5RXYkl9eaeqf6ZJxPiho2c8nNvTAGLO0zc ccOuaPJ5MfICQqNxEGyn/mZVopwRYugBeqUkeeo= X-Google-Smtp-Source: AGHT+IH30I7c0CtI+edBTcurzoZbuGpVIRTDkszIvnJKH1Zuh+Q1uQQ70sGHOgxf0j2xkRawwp0SAA== X-Received: by 2002:a5d:5f91:0:b0:38f:503a:d93f with SMTP id ffacd0b85a97d-390eca480f2mr3759250f8f.40.1740755857224; Fri, 28 Feb 2025 07:17:37 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:36 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Tomi Valkeinen Subject: [PATCH v3 1/9] i2c: atr: Fix lockdep for nested ATRs Date: Fri, 28 Feb 2025 17:17:18 +0200 Message-ID: <20250228151730.1874916-2-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Tomi Valkeinen When we have an ATR, and another ATR as a subdevice of the first ATR, we get lockdep warnings for the i2c_atr.lock and i2c_atr_chan.orig_addrs_lock. This is because lockdep uses a static key for the locks, and doesn't see the locks of the separate ATR instances as separate. Fix this by generating a dynamic lock key per lock instance. Signed-off-by: Tomi Valkeinen --- drivers/i2c/i2c-atr.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index 8a5d9247fd29..f6033c99f474 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -68,11 +68,13 @@ struct i2c_atr_alias_pool { * @atr: The parent I2C ATR * @chan_id: The ID of this channel * @alias_pairs_lock: Mutex protecting @alias_pairs + * @alias_pairs_lock_key: Lock key for @alias_pairs_lock * @alias_pairs: List of @struct i2c_atr_alias_pair containing the * assigned aliases * @alias_pool: Pool of available client aliases * * @orig_addrs_lock: Mutex protecting @orig_addrs + * @orig_addrs_lock_key: Lock key for @orig_addrs_lock * @orig_addrs: Buffer used to store the original addresses during transmit * @orig_addrs_size: Size of @orig_addrs */ @@ -83,11 +85,13 @@ struct i2c_atr_chan { /* Lock alias_pairs during attach/detach */ struct mutex alias_pairs_lock; + struct lock_class_key alias_pairs_lock_key; struct list_head alias_pairs; struct i2c_atr_alias_pool *alias_pool; /* Lock orig_addrs during xfer */ struct mutex orig_addrs_lock; + struct lock_class_key orig_addrs_lock_key; u16 *orig_addrs; unsigned int orig_addrs_size; }; @@ -100,6 +104,7 @@ struct i2c_atr_chan { * @priv: Private driver data, set with i2c_atr_set_driver_data() * @algo: The &struct i2c_algorithm for adapters * @lock: Lock for the I2C bus segment (see &struct i2c_lock_operations) + * @lock_key: Lock key for @lock * @max_adapters: Maximum number of adapters this I2C ATR can have * @alias_pool: Optional common pool of available client aliases * @i2c_nb: Notifier for remote client add & del events @@ -115,6 +120,7 @@ struct i2c_atr { struct i2c_algorithm algo; /* lock for the I2C bus segment (see struct i2c_lock_operations) */ struct mutex lock; + struct lock_class_key lock_key; int max_adapters; struct i2c_atr_alias_pool *alias_pool; @@ -679,7 +685,8 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, if (!atr) return ERR_PTR(-ENOMEM); - mutex_init(&atr->lock); + lockdep_register_key(&atr->lock_key); + mutex_init_with_key(&atr->lock, &atr->lock_key); atr->parent = parent; atr->dev = dev; @@ -707,6 +714,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, i2c_atr_free_alias_pool(atr->alias_pool); err_destroy_mutex: mutex_destroy(&atr->lock); + lockdep_unregister_key(&atr->lock_key); kfree(atr); return ERR_PTR(ret); @@ -723,6 +731,7 @@ void i2c_atr_delete(struct i2c_atr *atr) bus_unregister_notifier(&i2c_bus_type, &atr->i2c_nb); i2c_atr_free_alias_pool(atr->alias_pool); mutex_destroy(&atr->lock); + lockdep_unregister_key(&atr->lock_key); kfree(atr); } EXPORT_SYMBOL_NS_GPL(i2c_atr_delete, "I2C_ATR"); @@ -757,8 +766,10 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc) chan->atr = atr; chan->chan_id = chan_id; INIT_LIST_HEAD(&chan->alias_pairs); - mutex_init(&chan->alias_pairs_lock); - mutex_init(&chan->orig_addrs_lock); + lockdep_register_key(&chan->alias_pairs_lock_key); + lockdep_register_key(&chan->orig_addrs_lock_key); + mutex_init_with_key(&chan->alias_pairs_lock, &chan->alias_pairs_lock_key); + mutex_init_with_key(&chan->orig_addrs_lock, &chan->orig_addrs_lock_key); snprintf(chan->adap.name, sizeof(chan->adap.name), "i2c-%d-atr-%d", i2c_adapter_id(parent), chan_id); @@ -835,6 +846,8 @@ int i2c_atr_add_adapter(struct i2c_atr *atr, struct i2c_atr_adap_desc *desc) fwnode_handle_put(dev_fwnode(&chan->adap.dev)); mutex_destroy(&chan->orig_addrs_lock); mutex_destroy(&chan->alias_pairs_lock); + lockdep_unregister_key(&chan->orig_addrs_lock_key); + lockdep_unregister_key(&chan->alias_pairs_lock_key); kfree(chan); return ret; } @@ -872,6 +885,8 @@ void i2c_atr_del_adapter(struct i2c_atr *atr, u32 chan_id) fwnode_handle_put(fwnode); mutex_destroy(&chan->orig_addrs_lock); mutex_destroy(&chan->alias_pairs_lock); + lockdep_unregister_key(&chan->orig_addrs_lock_key); + lockdep_unregister_key(&chan->alias_pairs_lock_key); kfree(chan->orig_addrs); kfree(chan); } From patchwork Fri Feb 28 15:17:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869959 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.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 4B0B7270EB9; Fri, 28 Feb 2025 15:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755864; cv=none; b=SrhS3SgTPDKDjAiyYCk3FRwD1looCz0RO+5KHCfJ6U5Z+vrR6TYjbiAczOR02KKkksWiRcxpKie2BkR3uRsa9j/SG2fo6dNEsnwTQJpqbcL7Ohj6M5A6eZ6M0BtgX7zr5m/QDzIpyyUyr03OsXmxb95OPjmjQhbHOmU1uXKW1+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755864; c=relaxed/simple; bh=PISapsmI9qRM5gfeVkdF4JKCyiQMUadO3rWiMlD7RFg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BAuhc82GS9yetCmOVnTwBDyaKkNZxYH3mZm58FxJKy7Y68Krvi3MV8jb+bYNPSUIvpbqRA+VMajpNUSdf0bL9Nyk6EKLPJfv/BnQ5V8NxzR5eGqFjyY1/9/BpkVFNKwQstXs8ur+Vxc7Mxqc5azQP4FFUklJgVO+4jsVKLlnnkc= 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=Kfx+Y2uq; arc=none smtp.client-ip=209.85.128.42 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="Kfx+Y2uq" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43948021a45so20943745e9.1; Fri, 28 Feb 2025 07:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755860; x=1741360660; 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=02Nk7Tu7oSWRbXywdmWr43MleXDMMaL38pYc/cnl7sc=; b=Kfx+Y2uqOeSYkCYg6i7Z7mz+wCagYaNAWzUQaDuMdUnFFQ5GThC2FfqDslSRy6xBpr 4uPzxk9ULoeFbS9zXfAxmafaUMOjzePKs1NxErmLYlcJoitGqU36K0N9wtW+yDb5zDy0 n5CaC4tXyf/c5MsFJaW8xmD7KRkNo7RTblewDrcELjQyM6I2f9eUywORjZAOceAi/Ctr pPmTfk+yEvrql3TCPSwpvzEOFe5CBMRySvdzdfzx7gH4+pTQBLutJIkZEtyCbGmsMZP9 0aPUtBHjCcHR+MWXLBSql70h6HYKBaUPnleWAU8ljRIhF37H3kMKbjE2+HCbCkRCCptf u2gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755860; x=1741360660; 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=02Nk7Tu7oSWRbXywdmWr43MleXDMMaL38pYc/cnl7sc=; b=mLpKMReayU0vS407AwogwNnShUn07q1oFlkYd01tVZw2J86Kjb0ZnqRNX2VHyx6u+L 3X18KeYLjyPen3I8hhKbW03XVg07tXmz0UXkhlkNLx2vxpXT75NiB09f9dSkllQQzf++ LYeZgMftxYYp3EpK2GcRDGsD4UDCxZsI1MAipyeVbyhDvYLeoQOpqpWG2E0/44SQaJo8 /tJ5QhoLtJnI3q3Mghdrq9H0dg20KFr5sPjLDDuP5HUMEYfpwfXPUv76uwguUQgQE1DM sJewOkdXGd9gmgc2ZPwYRmW8ahVR9MQZmwc2RkbOGU4lrNwqwqVEKb2vWiwLZlqkiWOC w7Kw== X-Forwarded-Encrypted: i=1; AJvYcCVb1Esf95XSv6eHOqEFh0gOCjqVJdEtc6BajbLG+E71o/XP5XgJlDRav9mFAjYfFy/d30utDZz4PTBaa3c=@vger.kernel.org, AJvYcCWEcGZylbDgj/hUWDb8cnvvM1ypG5QUwUfXOoUrGvchdPL4XyV2N/vUdlKYPkmw3Q2yy7nMYUKR/nw=@vger.kernel.org, AJvYcCXf2jVrgJJ+egj2NQ84HQNAMTStpPYIundu4iCw53AArXP/EuxmIpfXT9nmW6RSn3/T5AvmwT8NFAYsDE6t@vger.kernel.org X-Gm-Message-State: AOJu0YzZQ2lFyre4hwsylaWcppxQlm7eJiGAHv/fjS08iySNez+agHJR D8Z9TTqpl2FWKhR+UMdMcdfqS0RiJIr6F2FGAYUX0SAxBdS0dfVI5FzOqg== X-Gm-Gg: ASbGncufXJ0XRp1/wID4THgEC8NfPAfXmS4F6JEPAUaq7WWqnAjIk32L/zc2tUeaXmr 2ZAIhxT6wSCb+gzIQPaLobVWi+dnjfi3CP4TSRArLsH4bAHc7eBRAenik4vZ1C/I9dizwqaoEFH VPV2YwhNrjI2Z636b+EfScS3aQ3+c48DSYkPO6melUj4oDvQlcBzBwHtWhFvVzN2Ndvu857PRw1 TU8G4S42sB+Yu7bAM8Jb+vHGIP5iPpuuxVHr5NE9flhJNBEHpmpQcj1j6jO+AKzpJ+G0lMgLzCr 41ri8uHR/vblLNzEedlqGcrMp/yqiqx/EuoB1tU= X-Google-Smtp-Source: AGHT+IHcIB5ih5Ak8ppnNtMqhEvkT6Vs/Y4qVpmCkLaNLy1wDcK5il5rG5f5hboByH0/Kq+vw747Bg== X-Received: by 2002:a05:600c:5101:b0:439:44eb:2d81 with SMTP id 5b1f17b1804b1-43ba67107c4mr34481015e9.15.1740755859451; Fri, 28 Feb 2025 07:17:39 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:39 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 2/9] i2c: atr: find_mapping() -> get_mapping() Date: Fri, 28 Feb 2025 17:17:19 +0200 Message-ID: <20250228151730.1874916-3-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A find operation implies that a null result is not an error. Use get naming to clarify things and to prepare for splitting up the logic inside this function. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index f6033c99f474..f2485d1670a2 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -241,7 +241,7 @@ static void i2c_atr_release_alias(struct i2c_atr_alias_pool *alias_pool, u16 ali /* Must be called with alias_pairs_lock held */ static struct i2c_atr_alias_pair * -i2c_atr_find_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) +i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) { struct i2c_atr *atr = chan->atr; struct i2c_atr_alias_pair *c2a; @@ -335,7 +335,7 @@ static int i2c_atr_map_msgs(struct i2c_atr_chan *chan, struct i2c_msg *msgs, for (i = 0; i < num; i++) { chan->orig_addrs[i] = msgs[i].addr; - c2a = i2c_atr_find_mapping_by_addr(chan, msgs[i].addr); + c2a = i2c_atr_get_mapping_by_addr(chan, msgs[i].addr); if (!c2a) { dev_err(atr->dev, "client 0x%02x not mapped!\n", @@ -428,7 +428,7 @@ static int i2c_atr_smbus_xfer(struct i2c_adapter *adap, u16 addr, mutex_lock(&chan->alias_pairs_lock); - c2a = i2c_atr_find_mapping_by_addr(chan, addr); + c2a = i2c_atr_get_mapping_by_addr(chan, addr); if (!c2a) { dev_err(atr->dev, "client 0x%02x not mapped!\n", addr); @@ -536,7 +536,7 @@ static void i2c_atr_detach_addr(struct i2c_adapter *adapter, mutex_lock(&chan->alias_pairs_lock); - c2a = i2c_atr_find_mapping_by_addr(chan, addr); + c2a = i2c_atr_get_mapping_by_addr(chan, addr); if (!c2a) { /* This should never happen */ dev_warn(atr->dev, "Unable to find address mapping\n"); From patchwork Fri Feb 28 15:17:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869421 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 0345F270EA4; Fri, 28 Feb 2025 15:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755864; cv=none; b=tn+Uha1J3hnjEfKQ9zcyNPMzCXwwENkWI7HwZ0P7xa+fr9XR/FxsrMKZQCT/uX2SzkhtoA8A6h7VvfnTuI/bLUdCa9UxunaukFv1MElinSGuK+pgcqa9ezLaZ8uVws8dMJvVWweI7QITup+CVAMJlaAD7MZeRKZidMHsGOolwM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755864; c=relaxed/simple; bh=btY97WZkaRxfvJGaZV4/irpvLakBopADE7uOu87iIqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oAYsNtvcnFtbrYAfYEF7Ags9fuRSPUToE43nth3IajfLzvn0sVJlqoYrszL3XVZLBisvVjey3/rIxh6mTh9ycmwJek4akG4zmPuyFGA+pgi6Aha70Dct/r3exGvEAguLmJk7RyLkzTiQRlSS0kdjKbbf+W+umr+hgt2rox+UKNc= 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=nATbu7EY; arc=none smtp.client-ip=209.85.128.45 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="nATbu7EY" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43989226283so15044735e9.1; Fri, 28 Feb 2025 07:17:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755861; x=1741360661; 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=S4qqqIezndnbu9odHIxE2+Bj8cVf+2ZH/Pr987aq8jU=; b=nATbu7EYaLKu6/JI2/5lLWF8cgkU2vZHhLqi3IxZpCbiFUgNK8gNLKNfTCuu9vai0/ iVQ3utg9MKjCJRx+Rs8Ywu57JAuMhf9MRboGlHmuA+c0mMv8WX6gUJnlzGBhhPdxR33u xOlRV/cAhR5pYiTmi++P3AOp4XNv3FD08ypfIChXHh9QK/ecsF1BsVhsaiGsaWrt85Jx 0IhCqnoTWduMQ0DY5Im0rV2iFbgxbbIOglypNnpPYGLZD/F7xQhJRY/+GuM5cdAMin2I d3V5GT3ruTy1sJ2ZUOOrKRfHgEbZylrfY0e1+JqtVJX0CwCUUEvQVC3GzYzg4mN7RUh4 ym8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755861; x=1741360661; 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=S4qqqIezndnbu9odHIxE2+Bj8cVf+2ZH/Pr987aq8jU=; b=uhAMFeocLAj212s00wqmm2w5KvR5X88T0UtFNJtSuFrLTVBh6wVam88rUpYHe5ib+o 10yyAiieAowKvOPyXBdMY5jUTQzhnTF69cCp/l81y5/VOVOJhEdIH9XTrB/QXfnwZq0+ O4hByfViJr500fwUlibOV4na0Rap1n99TqG8JPSOzHB82vbciSfulIY6xy/mYOwVxr5K bExoyDMATjvCq/PW3rVN9DewsB9DM+4wBI6UuBZctJFSCU53RS+C6cn07ieFHAZkJ1eK Oj3i7auUBivXVvpcWBD1Kjcqw9Lc+8/zE4ySCGZE3EucAPZ1KpZrL+ZSSfHSMNNzJr/u 80rQ== X-Forwarded-Encrypted: i=1; AJvYcCUjOGM4aPGVfThJ5gQxIeY/lj/OXNSMIntYOH+HAO2o1sZ3RM5YNeLkDGkM+htOTDz1S9iASJr6fOU=@vger.kernel.org, AJvYcCVVljFB+35+6ntdAWj77gU2HR2cO2eDgZzu5zVcBR2E65J3RJW1q2GPqPrrvkPQTnEIRjAO1bOaSNjVmG8=@vger.kernel.org, AJvYcCWCpGVHHKEKjVLiXd7Jl6DdB49dyjvEImxMcobm6X8VU43cFUHSiIu/AznEvAZPJRR6NAKA1mS3a8ZIWZi8@vger.kernel.org X-Gm-Message-State: AOJu0YzI/mgI7fvz5cKbA8hyDiLexO4SjggdueQ1a82cnVLflBzkG0eh dg6Mz7wT1S6pfD5/NYc6jZAj7lOc23TNBV/siatwUcNK98U0vewR X-Gm-Gg: ASbGncsHaYPwL278/WInZI8cJ1EXwWl4mCGHE+h+c4f3KUV27PKp31F3rJ4K+XE8Gol p5HDp+qnk38kB2Vu50kefOT84MkRHAr1rCppxikFRs0mWqz9X79NI6VQ23WYjOrCGHU9M175W2m uZ4Y7e6Yo8eQPOIS2HW/SS025nrPZdvGvdQ3OsOkPJ0in+dNspq0TPJ/iX4oeUNub8sdfadqKHn 2t5NGzDYQ/u/h62TLZ3Hq4H5eStRv/kFZqS/FdAQYrrFg4Arm6fJRzMQpbkLPJL5eKa/2/gHUp+ gVlNlQwfkmMC4bvF2sUb9psOWNfWLS6GMDE9iig= X-Google-Smtp-Source: AGHT+IFj0DbA75z47DexBVK3a9hAgTjGol+BBEne4fOVKGatR0z7tCNeQN0gg2MRn9Z+nbrtgRypGw== X-Received: by 2002:a05:600c:4685:b0:439:9a5b:87d4 with SMTP id 5b1f17b1804b1-43ba67047bemr31688125e9.13.1740755861070; Fri, 28 Feb 2025 07:17:41 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:40 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 3/9] i2c: atr: split up i2c_atr_get_mapping_by_addr() Date: Fri, 28 Feb 2025 17:17:20 +0200 Message-ID: <20250228151730.1874916-4-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The i2c_atr_get_mapping_by_addr() function handles three separate usecases: finding an existing mapping, creating a new mapping, or replacing an existing mapping if a new mapping cannot be created because there aren't enough aliases available. Split up the function into three different functions handling its individual usecases to prepare for better usage of each one. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 104 ++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index f2485d1670a2..fc92ed930877 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -239,9 +239,23 @@ static void i2c_atr_release_alias(struct i2c_atr_alias_pool *alias_pool, u16 ali spin_unlock(&alias_pool->lock); } -/* Must be called with alias_pairs_lock held */ static struct i2c_atr_alias_pair * -i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) +i2c_atr_find_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) +{ + struct i2c_atr_alias_pair *c2a; + + lockdep_assert_held(&chan->alias_pairs_lock); + + list_for_each_entry(c2a, &chan->alias_pairs, node) { + if (c2a->addr == addr) + return c2a; + } + + return NULL; +} + +static struct i2c_atr_alias_pair * +i2c_atr_replace_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) { struct i2c_atr *atr = chan->atr; struct i2c_atr_alias_pair *c2a; @@ -253,38 +267,54 @@ i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) alias_pairs = &chan->alias_pairs; - list_for_each_entry(c2a, alias_pairs, node) { - if (c2a->addr == addr) - return c2a; + if (unlikely(list_empty(alias_pairs))) + return NULL; + + list_for_each_entry_reverse(c2a, alias_pairs, node) + if (!c2a->fixed) + break; + + if (c2a->fixed) + return NULL; + + atr->ops->detach_addr(atr, chan->chan_id, c2a->addr); + c2a->addr = addr; + + list_move(&c2a->node, alias_pairs); + + alias = c2a->alias; + + ret = atr->ops->attach_addr(atr, chan->chan_id, c2a->addr, c2a->alias); + if (ret) { + dev_err(atr->dev, "failed to attach 0x%02x on channel %d: err %d\n", + addr, chan->chan_id, ret); + i2c_atr_destroy_c2a(&c2a); + i2c_atr_release_alias(chan->alias_pool, alias); + return NULL; } + return c2a; +} + +static struct i2c_atr_alias_pair * +i2c_atr_create_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) +{ + struct i2c_atr *atr = chan->atr; + struct i2c_atr_alias_pair *c2a; + u16 alias; + int ret; + + lockdep_assert_held(&chan->alias_pairs_lock); + ret = i2c_atr_reserve_alias(chan->alias_pool); - if (ret < 0) { - // If no free aliases are left, replace an existing one - if (unlikely(list_empty(alias_pairs))) - return NULL; + if (ret < 0) + return NULL; - list_for_each_entry_reverse(c2a, alias_pairs, node) - if (!c2a->fixed) - break; + alias = ret; - if (c2a->fixed) - return NULL; - - atr->ops->detach_addr(atr, chan->chan_id, c2a->addr); - c2a->addr = addr; - - // Move updated entry to beginning of list - list_move(&c2a->node, alias_pairs); - - alias = c2a->alias; - } else { - alias = ret; - - c2a = i2c_atr_create_c2a(chan, alias, addr); - if (!c2a) - goto err_release_alias; - } + c2a = i2c_atr_create_c2a(chan, alias, addr); + if (!c2a) + goto err_release_alias; ret = atr->ops->attach_addr(atr, chan->chan_id, c2a->addr, c2a->alias); if (ret) { @@ -302,6 +332,22 @@ i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) return NULL; } +static struct i2c_atr_alias_pair * +i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) +{ + struct i2c_atr_alias_pair *c2a; + + c2a = i2c_atr_find_mapping_by_addr(chan, addr); + if (c2a) + return c2a; + + c2a = i2c_atr_create_mapping_by_addr(chan, addr); + if (c2a) + return c2a; + + return i2c_atr_replace_mapping_by_addr(chan, addr); +} + /* * Replace all message addresses with their aliases, saving the original * addresses. From patchwork Fri Feb 28 15:17:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869420 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 AD135271269; Fri, 28 Feb 2025 15:17:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755866; cv=none; b=oRhvUVAJJXuIMowUiAOT2wdZWxNrhuZoN3jmhoVIQAHXkJRxxIz8SjTJHceS4MTNRDIw9Q/oQ0C0q94Mf0c4FsoHgSj9moYHAuGdOQKDV5LQFf0WSaR5vrNOrNKHVSNaqz5LzFqKlpbNB6/lGQBvm1t0+5HcE7fk4L0zxj4TAqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755866; c=relaxed/simple; bh=xaw+9NRhj93i8+l2AzjUn7HMcyjC5D4eiOuWNB1OLiI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ih96G/av1DS1aFdvbJsLe6cnwmyJ6HmVDAyLel5xG+yDqAWNxd2dnr+M7BOL5ETz1iReuXtB+uUJFdqo+2pF/2woZGkp34o3SXA9WISKKqt/qzYgFLYJjXl58AghHeAXAFaudD3A4jVC1gQDreIZEtU4gwwi5h70kwbzHrk48So= 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=IH1lo25b; arc=none smtp.client-ip=209.85.128.44 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="IH1lo25b" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-439a4dec9d5so24112035e9.0; Fri, 28 Feb 2025 07:17:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755863; x=1741360663; 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=R6M+HRPCEe7YtMaRAGBz1VKfF9YRyuQoo35/cd6V73U=; b=IH1lo25bk/LwGKhNSVHsgMJtbcpXfW9PUVYNxa60V2EiuhD8f+xI4AQRQVNOaKdUeF YXdpwlmM8mVcW04F9cVRk7CfuIE/Qec9iLtbr3qWQejnWdTcZr+IrtJLDa7abhtiWjYx hHy2mpvn149EYTDxD46Ll1y6+G8RV113V6BXX6ImjGUVoumgVG5OgB3eKXwYu74ySj9j BbN7DLZ9nuPCJiZwP24f9IBjoIBV6LKDqZj/AJcWjui/3gXxmBOndclTu2ZqMmzMYYIo 5Sybl/hz21f+r9AHBVU5LwIuqWlylzhbxpXNo+4shXdUABGqOgAkEQHmcapQAyVnwiEA kWsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755863; x=1741360663; 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=R6M+HRPCEe7YtMaRAGBz1VKfF9YRyuQoo35/cd6V73U=; b=TjOc59f67NVFXwcvqc2POJfyZfILo3y/IwIvFpHHeeWWeNgdBvoGsDHkDS0np3Rzqi 5auBvIfPFKfENJY6Xp0cGk+H+s+7kfFwWhURvVuVWENAt/bgoduyyXuNADGr8eIDcD2E WGeFU5/YSZZE3Dig8yLgziw0+MLdl6WlemnD0EQRyA9uEoaDHLvoam0wxNMpwd4aohO0 JJwMD3A4wKVLg40+Q4CaXOGV8WSHBV6v3P15aRuGJr/lgHE2q1RoQiBkZ9gdYc2RLq46 bUiYLvutAuPgmey+ofFl0i8sjCwAZf4oopFZLkNMQ881OEnoEtds4DLT51kQX6ogaf3M +dzA== X-Forwarded-Encrypted: i=1; AJvYcCUNfDGbVY67xSHt99omAfbJlY7AxQE3TSpjSYDQtfbnihw6LB8E3KcHSyhAyslCPfRNSgGL9FX286ThcGTn@vger.kernel.org, AJvYcCVVgD1MRRj+FbNspPRvxNbeYbu5j08opVBe/MioXjp0RCkiWAjspwua4b293y0G4Ox9HvFkKDzHMyDMcPs=@vger.kernel.org, AJvYcCXdiWmgPWzOihQfsKzSXOj5B3KMwC8aBqEZN5K7M0ITlE4R39k3sI9I2JArghTtOv15zO9tPbOkxv0=@vger.kernel.org X-Gm-Message-State: AOJu0YzBqYFkhwPS5S4XBy6mF3aVO1+BSYNZlSzLRzcDHWpeh70nQ43A OIzMjfpvtGtjZniKov7l3X6gOBtNO9uXlvOUOILU2dRwR27diYRm X-Gm-Gg: ASbGncuby/LY9LNrhvqu0mRN/sERMeJ1jbmXlSErkfCQQgs4si6qwId37HUBRBzIHsO rgG1qDQzYQqIcRgcdZxmtFp+sauoATcExoG6C2jaYR2ZMNJuwR4SB171v/J17XffWt027Kb30kn dRkuv5Lt86xW9YEd4DpYt77LrJrsgIVk1vlrBiFXYTfFJ2XLC7zAcqqJYbffTPh4ZX4Nc0RDoCS kcpU/d0oBYhb4G9OpbvCDMi+Hg0Mhmr0npvVcRCEKqp7pHtc88gs1WnNDcZIVeisNnjLEpR0RSc XvVL3K0ugM7wtBo+6UiUizR9HYKdqMPnlUpsCEU= X-Google-Smtp-Source: AGHT+IGjX1N9FuSMpvL6z7k6QiNoEMimLTVA9WqjWwuygtEnQasl6sngyDK/8LhugrBpn/WJmEWu7g== X-Received: by 2002:a05:600c:524f:b0:439:9106:c09 with SMTP id 5b1f17b1804b1-43ba675bafcmr30114585e9.26.1740755862623; Fri, 28 Feb 2025 07:17:42 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:42 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 4/9] i2c: atr: do not create mapping in detach_addr() Date: Fri, 28 Feb 2025 17:17:21 +0200 Message-ID: <20250228151730.1874916-5-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It is useless to create a new mapping just to detach it immediately. Use the newly added i2c_atr_find_mapping_by_addr() function to avoid it, and exit without logging an error if not found. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index fc92ed930877..148a7bb0508e 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -582,10 +582,8 @@ static void i2c_atr_detach_addr(struct i2c_adapter *adapter, mutex_lock(&chan->alias_pairs_lock); - c2a = i2c_atr_get_mapping_by_addr(chan, addr); + c2a = i2c_atr_find_mapping_by_addr(chan, addr); if (!c2a) { - /* This should never happen */ - dev_warn(atr->dev, "Unable to find address mapping\n"); mutex_unlock(&chan->alias_pairs_lock); return; } From patchwork Fri Feb 28 15:17:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869958 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.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 1373127293A; Fri, 28 Feb 2025 15:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755867; cv=none; b=a5y4xO7QrmsfbtIBukZeJtIOPHclXJyWtD/WJ6Yh+m17f/tRcT1MTtBaa0O0w5qHOhGeNxKN8rNzqiP/7If0M2EvoMR7/PQDkDzHLSxlkwaKwi3YZ1eQItxjkKfqn0UnGtWaEW71SG43reQj9RtPYodtDqY9BcmzWA5I8bqCUOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755867; c=relaxed/simple; bh=WfkXDrGvYN8uN/Bp7tosHJ2k1BK9SeNY3SSbh1LJ+8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PXEH+JAXB8JrYTvKODc63kJZg1ZMEpsTbtNFv9OuJ7ILgbvoAhXS2bVGvfZ21SjXA7R4qhMIvTcfQ0JzlNc1WvTZgL1nTo356deRlfvzPY+nZIlIGJomcgU3VXuE6c8waw+P0ozBQb0gng7Po8LSP0gBAT1c27UzGrZOVOQLiiU= 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=RgaYDgK1; arc=none smtp.client-ip=209.85.128.48 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="RgaYDgK1" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43996e95114so15948575e9.3; Fri, 28 Feb 2025 07:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755864; x=1741360664; 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=W5lOSBJvwe5uSEevcFk6UxLu7ZPFJZy2weUCb6t4qZU=; b=RgaYDgK1utDdu6b88ynczrxISrROpj4pBG2WUlZeyZb/8R3HG3SgeUUnfp4/lCkqFt mzi9+7IZkTViRnnmsdfr9eoPUK4B/TLrjQ4UMlELLBAKLU9Az7Km+pfaQGE92ClFGWZg I+BSN5mJNDRZr5uGdMIO0U4wtZsy3YiZycHmwDD9KI1BHAyzuhz3ncTxGt13anNCM7Nh JIQBLGkOft/mazWBaW7HYM+rzFAaSKbqfdxdYVY9MDtfNJsDo9tHQd3HjNXNpMRD+gpr t6C+7N/tXd1NWNElEiuWNE8V0M4Md1N07yMeflZGhZzwqcfrP/uZ35Z8CriSxI9Xpp4K rKZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755864; x=1741360664; 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=W5lOSBJvwe5uSEevcFk6UxLu7ZPFJZy2weUCb6t4qZU=; b=SXhtK+Zgtx50Scs0pdKiqknfhAXfCk4Wk+Y7HhxoNRrkcftVheZGiEektl+gFSbm5B aes4ztaeraeCZaUU9S1rSSY1kZ/mqh2pvviT74gbmu0MO8p2w98Wh97TZO+t8ALEBDH7 G5+v3sWpdAJHJvXGfn/bbvNji5NfCjdMe35NmhdJ8NbQA0ze9Gb2bMGav6731ZkMRA8n 3SAUcvU3U20VbKtql/abmnc8ZqUNeUaWIhqD9uXubCZlIFYBkbg1L3xSPY7gllaROGYP RAYiSG60lCbbIa5mdyttg9Dnck0MPJns4yTZ0l4510I3MDXiyBleK2nq5J5W+TI0dFS8 9XAQ== X-Forwarded-Encrypted: i=1; AJvYcCWkdmpFoLaoEDuWUQqOUfRq03oh3JjU90iDeDCDQ74KbrR8P6MPCpplMiiXTvjbipaV5xaTEOyMCdg=@vger.kernel.org, AJvYcCXmYPGDF1Z/95MpTetAG2oHAeBycgFBMFHlB5vxb5+eUQppk92fT0SvYxGTMA9/euTQMEaqOJ4t7Rx9a/4=@vger.kernel.org, AJvYcCXo0dTZxFGcnmHK5pXnSeF8B0YTy/jcoul9O+1L2HA5HfH0JMfUFVSlgV4A2jIPVQApTCzgBIVjutvLf5WD@vger.kernel.org X-Gm-Message-State: AOJu0Yw+bAllv13CgCYTaNGDvC2y3HHn64vMQpMZ+tZx2VISSfpRfQAz sJGWZSDD3evHxPnnfLZznqiNa8VVSMg6nMdS/5x8XRfsG8mEwGtm X-Gm-Gg: ASbGncuvE+1RPVJXybTO/qgw8D9h4wpfoDrLh4s/SDCnGOthAoeDMS8Viy6fy841SLH eDhg0x+ft/ZF3C91apoPfKYtSoa63qsDGdoBtXJXGVsHy1RZO5nT5VDSHgRlpPlheMILtnVeGtP F7MVPNSmjOXRtt9yv5+Fyo3DLapNIYkDWh3MQisa0KSBHzIQKEunrGgNmowOQi8Ls0iffHRiCJ5 Bohz3UqC3Jim0Sfwne5X4cINDQSJo0oigcB/yhfKGujmzmXS+gjQbRud/13KN03LDFqU0/rxmN3 i5ISGFcL5e2dkTrZ818PEoBO1AGZGX9qRAx/b3U= X-Google-Smtp-Source: AGHT+IEP1z2gYbKB4fBZrng7aoyZYKSP/V+gCCgx5zf9l4C+JfYPAcPo5iS7ng0+DCOZujB3CfGlQg== X-Received: by 2002:a05:600c:1c95:b0:439:9828:c42c with SMTP id 5b1f17b1804b1-43ba67606d9mr30993205e9.23.1740755864122; Fri, 28 Feb 2025 07:17:44 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:43 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 5/9] i2c: atr: deduplicate logic in attach_addr() Date: Fri, 28 Feb 2025 17:17:22 +0200 Message-ID: <20250228151730.1874916-6-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is the same logic as in i2c_atr_create_mapping_by_addr(). Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index 148a7bb0508e..b9d63efce8e3 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -534,38 +534,20 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter, struct i2c_atr_chan *chan = adapter->algo_data; struct i2c_atr *atr = chan->atr; struct i2c_atr_alias_pair *c2a; - u16 alias; - int ret; - - ret = i2c_atr_reserve_alias(chan->alias_pool); - if (ret < 0) { - dev_err(atr->dev, "failed to find a free alias\n"); - return ret; - } - - alias = ret; + int ret = 0; mutex_lock(&chan->alias_pairs_lock); - c2a = i2c_atr_create_c2a(chan, alias, addr); + c2a = i2c_atr_create_mapping_by_addr(chan, addr); if (!c2a) { - ret = -ENOMEM; - goto err_release_alias; + dev_err(atr->dev, "failed to find a free alias\n"); + ret = -EBUSY; + goto out_unlock; } - ret = atr->ops->attach_addr(atr, chan->chan_id, addr, alias); - if (ret) - goto err_del_c2a; - dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n", - chan->chan_id, alias, addr); + chan->chan_id, c2a->alias, addr); - goto out_unlock; - -err_del_c2a: - i2c_atr_destroy_c2a(&c2a); -err_release_alias: - i2c_atr_release_alias(chan->alias_pool, alias); out_unlock: mutex_unlock(&chan->alias_pairs_lock); return ret; From patchwork Fri Feb 28 15:17:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869419 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 9BE7E2755E5; Fri, 28 Feb 2025 15:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755869; cv=none; b=UoPrDE9rGKDv/awVOBbJymNx4adJtCMDqUDvmn903q+p2fo4YqYE0N0Lhyi940J9AHnQ2CgrL2jIU9RUjlvSItfEmCWm5BGybTT5jeiJ121XC+Xbh7AmlNi8cmbyxZ2KRVCeVoSAZ/xpaD7itVrfV/qJdOp/KCZ9hjyPvlPNkQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755869; c=relaxed/simple; bh=/W/QZFcRBnIM9b0Jt8Kw6hZJZD0btW20G7HvSU1nKE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FExhsIRcsDLH1Mk2jdLVV9f1uqIbsJfSCRMKOBSp1VK4maI9aTXeVTY3IboIbbRbsP1OErD1ZerOCw8bz6u4pN50qi7Sq6DRfoSlSD+ycF98OEd8ASAmYAWuG5gOVgjTlwFr/qzC4I8o0dOO43dOVxGY3kbJJdZIP14k/7aAnrA= 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=M6QGqm/+; arc=none smtp.client-ip=209.85.221.53 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="M6QGqm/+" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-390dd35c78dso1773449f8f.1; Fri, 28 Feb 2025 07:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755866; x=1741360666; 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=gTVzPUIvmiDHrwsxbjyL6sD0GFnHJnYahl0LLE8iGaw=; b=M6QGqm/+bN9pw+mhZAsAucr3/PsuNxBdduDzi1P7wpOqLwNodoYR+XdMzPjg6rNXOV UR8nJhL0UvKRYM6wIc9Z8fXner+O7fByk0loqK5hPN2VsNOSlOpWNIS5NiePfayL6KG6 41S0rlMzCrfK0MBmXL3YvPQbCgGSipzYvxxDQmWOWPu4rvIGue+zEq+KCQd8bun+GDQ3 artCZ1A5rg0XvlnMLZeuFF44oXwWDMZ8kU84Bw82fFI/ooSFhujUU7VZuwgjcyAKfMge YuqarCp8728npCQWwLANBg9rkf7i9uQL8eR96dlGKKvdWpUVi6SKo5SN+cEpFlBru7BR kI5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755866; x=1741360666; 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=gTVzPUIvmiDHrwsxbjyL6sD0GFnHJnYahl0LLE8iGaw=; b=XAjlCM0vC+vxO/V9w8y1HRW1TZV7/9hBREIrf0mld8aiLEStjmqi+B0o5Nhqb3eXMD WHY2fpcA/SSHXwupP2xrO/x1nK6wMG/d52NIzVNozCyjp8n/JJxv0uTwcBUBXdg8uPxO 8UCp0AJ8bBUi+GWwL+7DI3qArqEhl4tC0BV0GPgVc8OM5agkLfzxpprMtc4nTaL11NA7 e9h7p3C73z5HMEkfQo+miXTIkg3i9y3YbPLMlaYOMFQ9+IcDCe7ZUDP/MZ+GuZJu0CUx ON2EiMhIElSbpsB+74Ziyq7dbcrf8Fr0vGfIxVGiJYeu3e2djDhmk7mkCnZMgekRfqOk ualQ== X-Forwarded-Encrypted: i=1; AJvYcCUvpvqmhU1vx/apqMP1ywOcT/8erVe9pY8azzOoAc/sk7KIdPVN+28ZkG5Frt81UnHk5mg96DjUroo=@vger.kernel.org, AJvYcCWUzkL+4mQ4QuSTO/QBB1KF87E+GsXLgVgyGgJeKZfUA7PcGCOPohWmbOqTQlDyVV7oVa2bGGsqHlKn2EO3@vger.kernel.org, AJvYcCX5RrNVjJdojTECwh3bon4GOEwomrvsXlm+FQ1hJhaf5UL8XSn3y4y8dQpX4LPepoh6pmEeyFPdpK2+sU8=@vger.kernel.org X-Gm-Message-State: AOJu0YwgMPTmYVDMfEsmKr5WUwQf3J+EKNlbMlUmjCwQOUV1qluwQ36Q XHS/SnIT5H1iBIXY/CxQ7pPIaNiO1EI1mGwXBmpvqzONPi61FO0C X-Gm-Gg: ASbGncsixDxsMKlQAox8/qxne/KVX07bcmvWuM/Sou/dDVOBRFx6NwQgCffoeHnezYC V8hooEPTMyjxopWU/8FAPXRAeZua1Tmtnmb8rEdSKaXZk+ypTqEXx4ttERzK7TQv/6TJRccQ5bK lOh5/KwDi7iRUek5mTdoOAVYSMWMrAVUv0Lrjjn8QmASAMnrpIFAc8S2okjWtYrF+XukZ5jomU6 nVjCV28/5O5pxem8nsmxc5N6wB5Dvxnm4FMPd23g5kg1UTD/crOnw3QLf9ANxFlsqQztoWjwzDG PIXFYNbi1xb3RZHtsp4fPefwfIro9lP1FrLKNIU= X-Google-Smtp-Source: AGHT+IHP4tiUoF4VE5t8yqErlXRDEFrKzeoMsISgTFum/RclAe3Oe9nIDZoIagq+j0tO+qyJdJM/YA== X-Received: by 2002:a05:6000:2a4:b0:38d:d533:d9a2 with SMTP id ffacd0b85a97d-390e168d3demr7509038f8f.13.1740755865717; Fri, 28 Feb 2025 07:17:45 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:45 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 6/9] i2c: atr: allow replacing mappings in attach_addr() Date: Fri, 28 Feb 2025 17:17:23 +0200 Message-ID: <20250228151730.1874916-7-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 It is possible for aliases to be exhausted while we are still attaching children. Allow replacing mapping on attach by calling i2c_atr_replace_mapping_by_addr() if i2c_atr_create_mapping_by_addr() fails. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index b9d63efce8e3..80a76fe4bf51 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -539,6 +539,9 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter, mutex_lock(&chan->alias_pairs_lock); c2a = i2c_atr_create_mapping_by_addr(chan, addr); + if (!c2a) + c2a = i2c_atr_replace_mapping_by_addr(chan, addr); + if (!c2a) { dev_err(atr->dev, "failed to find a free alias\n"); ret = -EBUSY; From patchwork Fri Feb 28 15:17:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869957 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.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 1D8EB27602F; Fri, 28 Feb 2025 15:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755871; cv=none; b=FVJtPPE6m7z+ibB+iWUc3vg0djzzoS2b2o1+AIJQZ/Dp2x+xD6WWv/TkyC+eySYLjzz6cpfdbk/Edw9HRnmEX/jprKz6LDKEdnNjuU2yZN+nYZn5RSGgI5alo8lub507AP/myqVmMkYteE5JIFLU2Qc62LM8uiQzKwLHs7/ku1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755871; c=relaxed/simple; bh=ibCylPXjBgc2FHLI8Fp0ByxmvYZUrtJ6yUxl/i+JtB4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D/ynip75EWH5manoF1gXKB4POxtKt2uRKH+lPa1smqjKn/sb1pNj391o5nsxKIFXOAqJymnrgeAzpEtCswdDc9Y5aHHcFN4QMX8ITItgQo4sU0QEZbYeLhl98ETHPjcjkIkxIwz9UvLpCvm7ZuqYBGp4rKm6Kd1/EqziCiXi6gY= 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=V2IMOReV; arc=none smtp.client-ip=209.85.128.42 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="V2IMOReV" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4399deda4bfso15151935e9.0; Fri, 28 Feb 2025 07:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755867; x=1741360667; 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=17F8jSd86fgXEXfgeJWAHgHI2hl8MFGJk/kzd0Ybbcw=; b=V2IMOReVO6ZtqhiqoxKqnTJlk8v27AbN/rI/lJCWQo79S3wPuZ2xnkOpsmDD0L9Any mp/+RAVcC+Qo5ltApFeYEdjMgflu/IfN0ciFe9dWcT/GV8YFnOTcFjbwROwtG4jUhQgH 71Sx0sScCsR6Itz6sidvaf1CFE1Z/Ap25Z6iSEnl8zWKpMmCqmM7VZzeZPqckW+H7OqO 7JX5y7Ekm21uwd9eVvR1HhfLYFYZb0Ly/N4kHbihxUsztZj9pHBQtBhWRA87JIIpv0d2 gOtgd024N+CsH4Uwm278/MWc1JWZeipa/il4Ppo1U257xy10Q6wiHT1YK5YQg/484dGN sxBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755867; x=1741360667; 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=17F8jSd86fgXEXfgeJWAHgHI2hl8MFGJk/kzd0Ybbcw=; b=aT2UPboVNbVAVn/q6AhfgZTs5Z5AvkNd8J8f6p+XVqHZWSwGNXTufVxBT/WHeUykhh eMRA5OoM+IHSfBBq4OUZcKrc9cndQaoefJGeRYzERwbOlNULCfU7mVSoGdCp7b6TgchS 2MvltGA4AXuZ6FwI1YK4vsaNkhrjVEOX283AmjSWkm3XMIfXSqw+dY+hJFv8zHxxAEBB 9cCZhc+TPt3ETageEHZHafG1v3sDrk6Z4af9bKezQUBZ50pPIYc2uFJiyQtbgNYmsZLE 8DGiLDbKwL7hFkxBybCZ0SGWRrzeMpk4abtKxQYuG/MVfG0033Z1nzCOJfy7Rnl0yjQB WtTA== X-Forwarded-Encrypted: i=1; AJvYcCUJAEHVOesFYMpNoaSXCxpxf86STNKq1kEDf+H4NFqW1TX7feT54k1ldDnVEG1mQP3hEiJMkigRyT0MJYTb@vger.kernel.org, AJvYcCUoPH5Br4rdJrSxIMmejaJ7jElz4bdrWMn+kUGLJWjnW1XuYY6lbIPJ1ncMPnrqNi3/i7XmJOIIvtghbyw=@vger.kernel.org, AJvYcCXws/ZBOsDZ9ZFgS97a0VY6Pfog6Vs6NDUyVKciGDLOtCP1UFTmeIzzrVRl3bP/7zHQkc0VHK2TKnU=@vger.kernel.org X-Gm-Message-State: AOJu0YylnC74dV5EcVqlsbJrxHqM9K6RpMzoZh6EW0USQzTY49puR6eC RsmjIWJCv9XKLsIHMb7cXHvXG2UDYW+FMkYIvb0r36manUM+bINL X-Gm-Gg: ASbGncsCxwkw552xsQolBBfx1THNQkvrZD8ySAt45eg1KZrLSqpy7WIPBQ7DyST07/q 5X38xvrdv1lmU2K0svooxnXCSu6H5YoMgCpJs+yHD3xfaFgHXWrGh1v5ug9PlekXQPgSMm3LsIS mXzBvtfEYw5Uk+QVHVikW0L9jiFA9XFXDPguBQRMLjQgCsNNP8Ewyy0abxJ9qtiyiynhAc1lQxU q4GgpSiXToyIndm6UKJr/t1FeIwwis7nViJ2OFrQ8yxULZQsfdttsJPT/3TYpq7zbdrfRjYFDs7 aZx81f/mRCFS/75fcq9QmhVn/Qy5M1wVDvr1F04= X-Google-Smtp-Source: AGHT+IHUCCC1ZbzfmdybGFRCF44znxIZOOHkvN3g/bRKCJ4+JQ01IVGUGOvU111eCMRxYegqYl8+aA== X-Received: by 2002:a05:600c:1387:b0:439:91dd:cfa3 with SMTP id 5b1f17b1804b1-43ba6760305mr31995755e9.29.1740755867222; Fri, 28 Feb 2025 07:17:47 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:46 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 7/9] i2c: atr: add flags parameter to i2c_atr_new() Date: Fri, 28 Feb 2025 17:17:24 +0200 Message-ID: <20250228151730.1874916-8-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation for adding multiple flags that change the behavior, add a flags parameter to i2c_atr_new() and an i2c_atr_flags enum. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 6 +++++- drivers/media/i2c/ds90ub960.c | 2 +- drivers/misc/ti_fpc202.c | 2 +- include/linux/i2c-atr.h | 10 +++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index 80a76fe4bf51..b3ad70a9d5f8 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -106,6 +106,7 @@ struct i2c_atr_chan { * @lock: Lock for the I2C bus segment (see &struct i2c_lock_operations) * @lock_key: Lock key for @lock * @max_adapters: Maximum number of adapters this I2C ATR can have + * @flags: Flags for ATR * @alias_pool: Optional common pool of available client aliases * @i2c_nb: Notifier for remote client add & del events * @adapter: Array of adapters @@ -122,6 +123,7 @@ struct i2c_atr { struct mutex lock; struct lock_class_key lock_key; int max_adapters; + u32 flags; struct i2c_atr_alias_pool *alias_pool; @@ -699,7 +701,8 @@ static int i2c_atr_parse_alias_pool(struct i2c_atr *atr) } struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, - const struct i2c_atr_ops *ops, int max_adapters) + const struct i2c_atr_ops *ops, int max_adapters, + u32 flags) { struct i2c_atr *atr; int ret; @@ -721,6 +724,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, atr->dev = dev; atr->ops = ops; atr->max_adapters = max_adapters; + atr->flags = flags; if (parent->algo->master_xfer) atr->algo.master_xfer = i2c_atr_master_xfer; diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c index 869e32bd07e8..6f475bae94b3 100644 --- a/drivers/media/i2c/ds90ub960.c +++ b/drivers/media/i2c/ds90ub960.c @@ -1122,7 +1122,7 @@ static int ub960_init_atr(struct ub960_data *priv) struct i2c_adapter *parent_adap = priv->client->adapter; priv->atr = i2c_atr_new(parent_adap, dev, &ub960_atr_ops, - priv->hw_data->num_rxports); + priv->hw_data->num_rxports, 0); if (IS_ERR(priv->atr)) return PTR_ERR(priv->atr); diff --git a/drivers/misc/ti_fpc202.c b/drivers/misc/ti_fpc202.c index b9c9ee4bfc4e..f7cde245ac95 100644 --- a/drivers/misc/ti_fpc202.c +++ b/drivers/misc/ti_fpc202.c @@ -349,7 +349,7 @@ static int fpc202_probe(struct i2c_client *client) goto disable_gpio; } - priv->atr = i2c_atr_new(client->adapter, dev, &fpc202_atr_ops, 2); + priv->atr = i2c_atr_new(client->adapter, dev, &fpc202_atr_ops, 2, 0); if (IS_ERR(priv->atr)) { ret = PTR_ERR(priv->atr); dev_err(dev, "failed to create i2c atr err %d\n", ret); diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h index 1c3a5bcd939f..5082f4dd0e23 100644 --- a/include/linux/i2c-atr.h +++ b/include/linux/i2c-atr.h @@ -18,6 +18,12 @@ struct device; struct fwnode_handle; struct i2c_atr; +/** + * enum i2c_atr_flags - Flags for an I2C ATR driver + */ +enum i2c_atr_flags { +}; + /** * struct i2c_atr_ops - Callbacks from ATR to the device driver. * @attach_addr: Notify the driver of a new device connected on a child @@ -65,6 +71,7 @@ struct i2c_atr_adap_desc { * @dev: The device acting as an ATR * @ops: Driver-specific callbacks * @max_adapters: Maximum number of child adapters + * @flags: Flags for ATR * * The new ATR helper is connected to the parent adapter but has no child * adapters. Call i2c_atr_add_adapter() to add some. @@ -74,7 +81,8 @@ struct i2c_atr_adap_desc { * Return: pointer to the new ATR helper object, or ERR_PTR */ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent, struct device *dev, - const struct i2c_atr_ops *ops, int max_adapters); + const struct i2c_atr_ops *ops, int max_adapters, + u32 flags); /** * i2c_atr_delete - Delete an I2C ATR helper. From patchwork Fri Feb 28 15:17:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869418 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 A198D276056; Fri, 28 Feb 2025 15:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755872; cv=none; b=tPhL6RgXbDhfSBwGdFj6DgzwiwgFhzfTKsja9fAb54eNMIksriCHE7k9C1MZmiHvK2iFFqqRw4ATOw6S98urWNVo2d3an7lkTnEkEyejkpUG5qawxV28mvv0T3RaRGg9qVi7HQxWM3VT1WEaXZQaNvVDJH71JhRuPFy1ArDPEfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755872; c=relaxed/simple; bh=zySZKiDk2pU70jsTWXkfe6mit7pyCQg+lVYRE9yFqqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgs910y2NlVBDHcQlJcu8Ha6dW8jag4n/rTokqLMMCTpBlCWvxZpR4Ap7y5oZz5b/kCyDfVx06gJZjkgkUEIovtVH5EOujP+j/68RkJQxanla3lWYBB/6arWpWFKCG0eKGYRcCnLsmDhx2jYQtnpV/jbsweREt+wygEd3X3Hky4= 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=aK8b6/TH; arc=none smtp.client-ip=209.85.128.51 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="aK8b6/TH" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-439a4fc2d65so23726025e9.3; Fri, 28 Feb 2025 07:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755869; x=1741360669; 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=dH8Nv3XF23c+759r1qgbeESvQOxywxLnq33sKq9oyz8=; b=aK8b6/THC54rkJpHI54JMrGiWeZ8Gdal/ad1Nhq1hDS1dHnKZoxbG8kOO7bQVqQSbS wmQ154D6wjJt3QgbrEIlUur2BS/wQKQuFqATtgmwxPO4Hn5wsN+ZwSjK8ka2gJ/A6qAJ f1NDBa7qWDKhwXTq+bfNxIJpdPNBaRzCJgwQo8kjcWSR0x4CFugPr7NJOF0vyTpNrT6C 1noXKLjxFwyKQX7mRYWHm9rxEYGvtPUD58wVr1fOetAPPC20u3YPbJ+4UnaBeB5qDN+U OH6mNuj/giXCiWGP/BBh+Lg405iUkqauyHlCnVp6ihuW9uv4gWupijvVQDN7xjHP0T42 Rr3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755869; x=1741360669; 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=dH8Nv3XF23c+759r1qgbeESvQOxywxLnq33sKq9oyz8=; b=YFkki/DnGWKuGtfEYr1XLN3z9m+U6DcxQQVtV2gQJ9D+55BCObSl+aBSLHnHHt6PPa +Q3F63ICjmzWMY6HxX8OH9ovq+KrFtvG4q0HeNIxtv8Us2J83Ol6JFLk11TwK1dG8Q4n OT7Z7XzHcxg4C/FcQDILS3ZEVlTiczCjqxyonXcMCc6nsn9qXQV3KJvoh8545pE7WOdu kEmF5cfRYFkQBDdURLam2JaoVOjlbM6OYSI3RV1leoLIpsMy65Qhc2vrXPmGZqbxIcOw aAUdhGNS70wYn5E0zCL8Ho/Z/FML1g9j1WlDzaZ55wW3nf/NUqXCw2XoG0+zW0PpuMsw j4FQ== X-Forwarded-Encrypted: i=1; AJvYcCU6Zaz6zXui444bcFqkIi4TY29+hIMc8nFzYnvSGV4rttbESjCBMxQZVUOmB/wPt6Xk+jQ6y8vzi98=@vger.kernel.org, AJvYcCVxnfpOiSHsiC5/9n/ghySMvQC4nRrqYVSJI2IKBY7rNj6YtZpTPN+JFOF/oPLnV3vJFlkRpEdBPFxlAIE=@vger.kernel.org, AJvYcCWIoIYYKecCy8tMJMAfpLaf8aCHx3ZPh3PipV9JzjCX+GTxV6cAAiM2XhYm5QjcURLNzpda7DG+kWjtoPNN@vger.kernel.org X-Gm-Message-State: AOJu0Ywheazc2P4HEUTQsiTS6Ct3CJhZkHXOfrzadx1WKzSoOf/ydGp3 r/oNjB48U1qUUz365tSYoBzRDOHvvIppF2xvF5coBBlwRykscq7y X-Gm-Gg: ASbGncvhGA3chpzR75/YkFfuqcpBS8rZUNiIbVo4EKlmE+lxEHenhEhQjKwzPDA8mM9 yS0P4BHuHnodGl62RJCxe7YWwqkbDrNBlb6GJKnEOtP3TmcYejovxKPTuTap5Z8muWHs3TaX//D m5MWzjLu1fI9LJArlh8nRgvzNIJLLUueosntaL/8ABJj1Kd9oo2690yBj7TNbCGafeW1B+mP5+h ieWSJs7jaCjSz6NDqkcpF4svBev/dqzYYgk/LxvrVIJGnaI8vEosDWpMqBs6w4nZffX+rYDv7/W 8O+K5Xc40Y9FaDAwMGuiLhCdi1JY52HsbncK6+8= X-Google-Smtp-Source: AGHT+IGRCq0UXQ7og5IS+ewv0s/9Bb61n5faLSQSAEyZCLqb+fhWTneTwPRLwPq2lwsS5ZjxwOIIpw== X-Received: by 2002:a05:600c:1c05:b0:439:98ca:e39b with SMTP id 5b1f17b1804b1-43ba675c3bbmr40163335e9.29.1740755868753; Fri, 28 Feb 2025 07:17:48 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:48 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 8/9] i2c: atr: add static flag Date: Fri, 28 Feb 2025 17:17:25 +0200 Message-ID: <20250228151730.1874916-9-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some I2C ATRs do not support dynamic remapping, only static mapping of direct children. Add a new flag that prevents old mappings to be replaced or new mappings to be created in the alias finding code paths. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 6 +++++- include/linux/i2c-atr.h | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index b3ad70a9d5f8..699cf23185c0 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -337,12 +337,16 @@ i2c_atr_create_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) static struct i2c_atr_alias_pair * i2c_atr_get_mapping_by_addr(struct i2c_atr_chan *chan, u16 addr) { + struct i2c_atr *atr = chan->atr; struct i2c_atr_alias_pair *c2a; c2a = i2c_atr_find_mapping_by_addr(chan, addr); if (c2a) return c2a; + if (atr->flags & I2C_ATR_F_STATIC) + return NULL; + c2a = i2c_atr_create_mapping_by_addr(chan, addr); if (c2a) return c2a; @@ -541,7 +545,7 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter, mutex_lock(&chan->alias_pairs_lock); c2a = i2c_atr_create_mapping_by_addr(chan, addr); - if (!c2a) + if (!c2a && !(atr->flags & I2C_ATR_F_STATIC)) c2a = i2c_atr_replace_mapping_by_addr(chan, addr); if (!c2a) { diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h index 5082f4dd0e23..7c6a9627191d 100644 --- a/include/linux/i2c-atr.h +++ b/include/linux/i2c-atr.h @@ -20,8 +20,11 @@ struct i2c_atr; /** * enum i2c_atr_flags - Flags for an I2C ATR driver + * + * @I2C_ATR_F_STATIC: ATR does not support dynamic mapping, use static mapping */ enum i2c_atr_flags { + I2C_ATR_F_STATIC = BIT(0), }; /** From patchwork Fri Feb 28 15:17:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cosmin Tanislav X-Patchwork-Id: 869956 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.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 4495527781E; Fri, 28 Feb 2025 15:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755875; cv=none; b=PFrPlOHg5voSLz3SoyCGwN55DItwbA2yy2MtNLtH240t0M1uzcoVh1gjK4B4dacJulR+p8Hll+SFaIKby/evf9B6VCROlJV9oBTfqQ4Uggscc6bVwjX5nGmRFhRkGRtcEM/SXRpBM3qX2W+sOzy7iqS0cAXyCyxJQEv8Iz9cm38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740755875; c=relaxed/simple; bh=+c/cArmccdVpgW/XqUAwxxkRjm/IBO9LbeKsevVUHyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Krac9PrHdJnVwP4BxckZCnuXZEICoQi2Kz4uW6THvlkrwPsndLmZ47USSyTzWnORPxGJQS69cyzJA04y21J78nA94ZhoOg/9PDmCJV5z+eayDxX3VOmCq2gkhXtlrUXrMY7MwoZdl4VS+ur91cfw4QhY3re3ZJ+twmV9ja73M/w= 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=T9IxeuWp; arc=none smtp.client-ip=209.85.128.53 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="T9IxeuWp" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4398ec2abc2so20271525e9.1; Fri, 28 Feb 2025 07:17:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740755871; x=1741360671; 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=KXNpYBoe/Rd5GuuvNB+oq/lSRtvK1so1zgVywfK3t8s=; b=T9IxeuWpJ3ZkcmcQr4xUdpvh30E/cQWR4+8lpm5cZ9xDMODdQeYHpFepmWb7CeV+AI PaXUAFrpFTvUFP5AVGBdqn+ONmARED5p6PMVBTKtPaxlGuVUmknjO9vZ4rmj7UEtu1a0 VU7VCx6jAfoU0SgimnS08+d1n36qhi9OXw+a7DDLYYc+13OVVGKTSbiNLc8XUCzYAxip SuAXq7dDcMTXLUTlv5ZprY3Jr6uclQvyOvoIclgXRvlAF4SzPPAXKJm+Uk1pzLqWZho6 cqT67mQgyYiE2DDC+aUXFvexwZKS+pB2HlLypvFkiHz3/Z36yxLOmKTgXrOoL/ouLMEu zYAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740755871; x=1741360671; 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=KXNpYBoe/Rd5GuuvNB+oq/lSRtvK1so1zgVywfK3t8s=; b=eJvCk/OZMZQrMf6tZMyLkDwOch2bBDJkHbv1BdWGPn2DTQvi8dn0kWs/vy+Yb7sTgc iGSsaJRp6TiCPJjUAA9INqS518DIA42RkrpzyfkrK2RLl8mNFwOzo6Ev+uzE6j4WQGlk JXBCrseadyYb47rRzwzr8IOJv2fnHAi5R24oGzlYws6Q8s+1nQNqiVJdno/Gc/F7AYfv NvaXI6LBZJP6Gvuu16trOAEKprRRV4YVyXJVVfMGELC62Y/J+Fys9xbKzDAotYlJoHPf chFMMCeYbe6n+vZBLZ8vCIn7Jp6UzaJeD3w4GIpLfFRiayylBVQjrc0+oWCFQygXD9ui 00BA== X-Forwarded-Encrypted: i=1; AJvYcCU5783qmkKWn2aKo+yHW2hpp2CjeG0ocPs0iDPwOUUTQ49gcXbbvnu/+fIgZNi221+WSIQpDQtGPz8=@vger.kernel.org, AJvYcCWMTTcpIhlzRIZKMi8LZf04ApFHmymd+YPpd2Q1FjoKBtsR5G6L2Tg8l+uPA2o5z4fORoIzqo9k5DH2z1I=@vger.kernel.org, AJvYcCX+9/ob5Dvw1yNuuX8lh1XqJ3Z65GxfxsnKgaLfKqXs0WWxRcOxQ4EcKclowUZbl0KVXu4lLcl1XOPys7Iv@vger.kernel.org X-Gm-Message-State: AOJu0YwKfitdIPTTIZkL8Qga6sSP8DPYQLN7I8Zg4lFKI5FMkAFJaXzn SgYkHSvCcIDYyZcvAvMyZ8EZi8tF0JOf7l8cxg68K/XSJHwAwFcI X-Gm-Gg: ASbGncuk6LiKuQqZ7qqTORCbv0CfvvlfjTuH3kDumu5FIbJ6WNytJ42AwolfI9Ux501 f8tGju40QEn49z5U999JY4g4aXR3Jec53cQy6vzOjpnQGPN7sisa+VMFYPQ2toKzefltqcFZsdY 7Dlv1AURlnnP+qThNkCecfw7bzfo5EXmrWxUmr1QdTCe7OBpUWrIOro7V6d9iUrDvcdASIjf/aS +gzcrZj5ePmTCTfRTW5bwgEwrbG81+ZUr30Lk7mhCca3j3wD7lItwiGBOm3fXZFovWuK4OwxUP9 rryukpb5KzSbP4G1564GVH6wzf1fUgF/7czUwJM= X-Google-Smtp-Source: AGHT+IHgnDNSyRbxWFIVxBnQrBG4eQUmoRauNdsSwxjsBbalYes6/9RG6l4xH2PwkzDkC3v2abvGCg== X-Received: by 2002:a05:600c:1c8e:b0:43a:b0ac:b10c with SMTP id 5b1f17b1804b1-43ba6744a10mr25188575e9.26.1740755870539; Fri, 28 Feb 2025 07:17:50 -0800 (PST) Received: from demon-pc.localdomain ([188.27.130.21]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b694524c6sm63096825e9.0.2025.02.28.07.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 07:17:50 -0800 (PST) From: Cosmin Tanislav To: Cc: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Mauro Carvalho Chehab , Romain Gantois , Arnd Bergmann , Greg Kroah-Hartman , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Cosmin Tanislav Subject: [PATCH v3 9/9] i2c: atr: add passthrough flag Date: Fri, 28 Feb 2025 17:17:26 +0200 Message-ID: <20250228151730.1874916-10-demonsingur@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228151730.1874916-1-demonsingur@gmail.com> References: <20250228151730.1874916-1-demonsingur@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some I2C ATRs can have other I2C ATRs as children. The I2C messages of the child ATRs need to be forwarded as-is if the parent I2C ATR can only do static mapping. In the case of GMSL, the deserializer I2C ATR actually doesn't have I2C address remapping hardware capabilities, but it is able to select which GMSL link to talk to, allowing it to change the address of the serializer. The child ATRs need to have their alias pools defined in such a way to prevent overlapping addresses between them, but there's no way around this without orchestration between multiple ATR instances. To allow for this use-case, add a flag that allows unmapped addresses to be passed through, since they are already remapped by the child ATRs. There's no case where an address that has not been remapped by the child ATR will hit the parent ATR. Signed-off-by: Cosmin Tanislav --- drivers/i2c/i2c-atr.c | 7 +++++-- include/linux/i2c-atr.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index 699cf23185c0..c7d0a30e7c39 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -390,6 +390,9 @@ static int i2c_atr_map_msgs(struct i2c_atr_chan *chan, struct i2c_msg *msgs, c2a = i2c_atr_get_mapping_by_addr(chan, msgs[i].addr); if (!c2a) { + if (atr->flags & I2C_ATR_F_PASSTHROUGH) + continue; + dev_err(atr->dev, "client 0x%02x not mapped!\n", msgs[i].addr); @@ -482,13 +485,13 @@ static int i2c_atr_smbus_xfer(struct i2c_adapter *adap, u16 addr, c2a = i2c_atr_get_mapping_by_addr(chan, addr); - if (!c2a) { + if (!c2a && !(atr->flags & I2C_ATR_F_PASSTHROUGH)) { dev_err(atr->dev, "client 0x%02x not mapped!\n", addr); mutex_unlock(&chan->alias_pairs_lock); return -ENXIO; } - alias = c2a->alias; + alias = c2a ? c2a->alias : addr; mutex_unlock(&chan->alias_pairs_lock); diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h index 7c6a9627191d..f979b931ca05 100644 --- a/include/linux/i2c-atr.h +++ b/include/linux/i2c-atr.h @@ -22,9 +22,11 @@ struct i2c_atr; * enum i2c_atr_flags - Flags for an I2C ATR driver * * @I2C_ATR_F_STATIC: ATR does not support dynamic mapping, use static mapping + * @I2C_ATR_F_PASSTHROUGH: Allow unmapped incoming addresses to pass through */ enum i2c_atr_flags { I2C_ATR_F_STATIC = BIT(0), + I2C_ATR_F_PASSTHROUGH = BIT(1), }; /**