From patchwork Fri Aug 4 07:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13341355 X-Patchwork-Delegate: geert@linux-m68k.org 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 20C18C41513 for ; Fri, 4 Aug 2023 07:09:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234045AbjHDHJm (ORCPT ); Fri, 4 Aug 2023 03:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233351AbjHDHJl (ORCPT ); Fri, 4 Aug 2023 03:09:41 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9C3B110; Fri, 4 Aug 2023 00:09:37 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.01,254,1684767600"; d="scan'208";a="175584226" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 04 Aug 2023 16:09:37 +0900 Received: from localhost.localdomain (unknown [10.226.93.35]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 9B117419E612; Fri, 4 Aug 2023 16:09:33 +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 v6 3/4] i2c: Enhance i2c_get_match_data() Date: Fri, 4 Aug 2023 08:09:14 +0100 Message-Id: <20230804070915.117829-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230804070915.117829-1-biju.das.jz@bp.renesas.com> References: <20230804070915.117829-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@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: * 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);