From patchwork Fri Aug 4 16:17:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 710432 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8E4DC04A6A for ; Fri, 4 Aug 2023 16:17:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229499AbjHDQRy (ORCPT ); Fri, 4 Aug 2023 12:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjHDQRu (ORCPT ); Fri, 4 Aug 2023 12:17:50 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B51EB2; Fri, 4 Aug 2023 09:17:49 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.01,255,1684767600"; d="scan'208";a="175631504" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 05 Aug 2023 01:17:49 +0900 Received: from localhost.localdomain (unknown [10.226.93.35]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 71B5240116CC; Sat, 5 Aug 2023 01:17:45 +0900 (JST) From: Biju Das To: Wolfram Sang Cc: Biju Das , linux-i2c@vger.kernel.org, Geert Uytterhoeven , Dmitry Torokhov , Andy Shevchenko , Andi Shyti , Alexandre Belloni , Jonathan Cameron , linux-rtc@vger.kernel.org, linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v7 2/4] i2c: Enhance i2c_get_match_data() Date: Fri, 4 Aug 2023 17:17:26 +0100 Message-Id: <20230804161728.394920-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230804161728.394920-1-biju.das.jz@bp.renesas.com> References: <20230804161728.394920-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Enhance i2c_get_match_data() for a faster path for device_get_match_data(). While at it, add const to struct i2c_driver to prevent overriding the driver pointer. Suggested-by: Andy Shevchenko Signed-off-by: Biju Das Reviewed-by: Andy Shevchenko --- v6->v7: * Updated commit description by removing unnecessary wrapping. * Moved the patch from #3 to #2. * Added Rb tag from Andy v6: * Separate patch to prepare for better difference for i2c_match_id() changes. --- drivers/i2c/i2c-core-base.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 60746652fd52..7005dfe64066 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -116,20 +116,19 @@ EXPORT_SYMBOL_GPL(i2c_match_id); const void *i2c_get_match_data(const struct i2c_client *client) { - struct i2c_driver *driver = to_i2c_driver(client->dev.driver); + const struct i2c_driver *driver = to_i2c_driver(client->dev.driver); const struct i2c_device_id *match; const void *data; data = device_get_match_data(&client->dev); - if (!data) { - match = i2c_match_id(driver->id_table, client); - if (!match) - return NULL; + if (data) + return data; - data = (const void *)match->driver_data; - } + match = i2c_match_id(driver->id_table, client); + if (!match) + return NULL; - return data; + return (const void *)match->driver_data; } EXPORT_SYMBOL(i2c_get_match_data);