Message ID | 20221111143921.742194-2-linux@rasmusvillemoes.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp783707wru; Fri, 11 Nov 2022 06:51:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf5sx7HcNToT7GuEqFDPIeSYuLZKPHnBzBbHICDSAAFK9qKY/p/TxVjp64zM1D1dcueirlvR X-Received: by 2002:a17:907:962a:b0:7ae:39b4:7208 with SMTP id gb42-20020a170907962a00b007ae39b47208mr2029776ejc.766.1668178262431; Fri, 11 Nov 2022 06:51:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178262; cv=none; d=google.com; s=arc-20160816; b=nzUz5gsqMd0vLIrlzmyYYnJL5vnAw8SZ0KFemZaVVaB8LOMsxtndSzKnWg0vGjrS6W CAFF07uuTMaG6w3EsHW9EMIEvC+c6zfN+ePIdgGMbTnjAtbPBolAgfdpZG2f3jGEEZgI OS9lk1UruuGDUCDnuJQm5oES2jmX5JxPIrXyY8N/EmWJpG5enw9kyA0Sps2O5O08nFtG jDh6xNt9I2dUJl2PqpckCQfZiUt/oqX71coY6u6aW3S0fJ3o3jQSYJaFt/1mOUNnWupQ EfZLxVXWXgcQ8QpZPdzfjAOgFnEIOSZfuTBD0QP54G1DbUqtP6p90u8dbyDKvupB8zfs EELA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3BpIqKmaepR1SpUgklkTdQKDocBg8CsmOhHMlVS5EHA=; b=lx5Mcdyf3L4Sm968DmMkCUZV8m1h/5VYAtsixqQZV2WEpqw8gaTiSkeBClxtikPkjD pkEnSBfb61adfWKyZCC8e2JK0Zl9vl9ZNFPCFI8t6AhpdgH1aVQXR1Ey3JDy1vMrOLX9 ogSR+r6RcqDIAMuwRCySy6nUhGT9P0PSsVdGJGtLhfQD/xsFBLeCdTtETLAncPSjVhM0 SCJfIey93zC4l/IrVp/WE5EliUuwDOf0+PrGu2yDV3u+ycsSCZx0nyPO05OpZfKwBUap CtysNJgRIOKZXxh7a6fNdLZjnj5XI2kOSyOfhJ1yNwRmzW52eO5sCxtja+8krUe3ZHzX BC4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=DrM+gnHh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p27-20020a17090635db00b00780488c11bbsi1556035ejb.388.2022.11.11.06.50.35; Fri, 11 Nov 2022 06:51:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=DrM+gnHh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234698AbiKKOjv (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Fri, 11 Nov 2022 09:39:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234206AbiKKOjg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 11 Nov 2022 09:39:36 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A7E060372 for <linux-kernel@vger.kernel.org>; Fri, 11 Nov 2022 06:39:27 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id kt23so12993251ejc.7 for <linux-kernel@vger.kernel.org>; Fri, 11 Nov 2022 06:39:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; 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=3BpIqKmaepR1SpUgklkTdQKDocBg8CsmOhHMlVS5EHA=; b=DrM+gnHh97vdiwSHvs4Vlne0TO7c7w6abdslmDlScfvk00Y2RXCkV1/198Pr+SVcbm n84m7ML0SQY10/bU7IEnnEcKIHqkZ20R7/yCuFd2+jYTc3uRCe18o/7sh7Ix2V05Gdge f0lgC7FK/NGYosoVXQ1uY9SHIUGtr4TPm7JrI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3BpIqKmaepR1SpUgklkTdQKDocBg8CsmOhHMlVS5EHA=; b=SZ7b+yz4MhkPUMybVeSZD2qjZ4LCs13/FtsQoZ2ZbmJP5Pn5A8Uc57+K1GqVTksNVN GbpjD8pFy4Mocv46P7py6fxgJPmvM/5t/m/CrmhHBEfodb7S24erW5QFepjAcoP6bUsr rFT/XFFUKpiCKAHqNHJkmyz/U4vK0UDyjsiTQmDuqUwFta42SmH0/k/CLbxsOXt/zKjf UF/5/TlvfQtKSV5TiPjewrmlP0hWQ5f1XdExSzfCPsqPEK4GzH++avMST0cxa/lVvY6g I3oSDVJGuUGWa/STtNIpAeQK+CICnzuS/xkli/ppsyb1b2gPjU5TNExOl9y/6mE+gW1x 3ltQ== X-Gm-Message-State: ANoB5pnD5IT9b0hSSCV7JcWmEtyDCA37kOhNSKU5W7idD06y50q0WYp3 jU+oN3Q4Kpc0Zo0yjBxrMAPcZg== X-Received: by 2002:a17:906:388c:b0:7aa:97c7:2c04 with SMTP id q12-20020a170906388c00b007aa97c72c04mr2100956ejd.191.1668177566016; Fri, 11 Nov 2022 06:39:26 -0800 (PST) Received: from prevas-ravi.tritech.se ([80.208.71.65]) by smtp.gmail.com with ESMTPSA id jt4-20020a170906dfc400b007a1d4944d45sm945886ejc.142.2022.11.11.06.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 06:39:25 -0800 (PST) From: Rasmus Villemoes <linux@rasmusvillemoes.dk> To: Cosmin Tanislav <cosmin.tanislav@analog.com>, Lars-Peter Clausen <lars@metafoo.de>, Michael Hennerich <Michael.Hennerich@analog.com>, Jonathan Cameron <jic23@kernel.org> Cc: devicetree@vger.kernel.org, Rob Herring <robh+dt@kernel.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] iio: addac: ad74413r: add spi_device_id table Date: Fri, 11 Nov 2022 15:39:17 +0100 Message-Id: <20221111143921.742194-2-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221111143921.742194-1-linux@rasmusvillemoes.dk> References: <20221111143921.742194-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749211689456435612?= X-GMAIL-MSGID: =?utf-8?q?1749211689456435612?= |
Series |
iio: addac: ad74413r: various fixups
|
|
Commit Message
Rasmus Villemoes
Nov. 11, 2022, 2:39 p.m. UTC
Silence the run-time warning
SPI driver ad74413r has no spi_device_id for adi,ad74412r
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
drivers/iio/addac/ad74413r.c | 8 ++++++++
1 file changed, 8 insertions(+)
Comments
On Fri, 11 Nov 2022 15:39:17 +0100 Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote: > Silence the run-time warning > > SPI driver ad74413r has no spi_device_id for adi,ad74412r > > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> > --- > drivers/iio/addac/ad74413r.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c > index 899bcd83f40b..37485be88a63 100644 > --- a/drivers/iio/addac/ad74413r.c > +++ b/drivers/iio/addac/ad74413r.c > @@ -1457,12 +1457,20 @@ static const struct of_device_id ad74413r_dt_id[] = { > }; > MODULE_DEVICE_TABLE(of, ad74413r_dt_id); > > +static const struct spi_device_id ad74413r_spi_id[] = { > + { .name = "ad74412r", .driver_data = (kernel_ulong_t)&ad74412r_chip_info_data }, > + { .name = "ad74413r", .driver_data = (kernel_ulong_t)&ad74413r_chip_info_data }, > + {}, Trivial, but prefer not to have a comma after a "NULL" terminator like this. It would never make sense to add anything after it in the array. Now you are matching existing driver style, but I'd still rather not see more instances of this added. Also, driver_data is not currently used. It should be because adding this spi_id table means the driver can be probed via various routes where device_get_match_data() == NULL. Hence, alongside this change you need to have a fallback to cover that case. Something along the lines of... st->chip_info = device_get_match_data(..); if (!st->chip_info) { struct spi_device_id *id = spi_get_device_id(); if (!id) return -EINVAL; st->chip_info = (void *)id->driver_data; //or better yet cast to the correct type I'm just too lazy to look it up ;) if (!st->chip_info) return -EINVAL; } > +}; > +MODULE_DEVICE_TABLE(spi, ad74413r_spi_id); > + > static struct spi_driver ad74413r_driver = { > .driver = { > .name = "ad74413r", > .of_match_table = ad74413r_dt_id, > }, > .probe = ad74413r_probe, > + .id_table = ad74413r_spi_id, > }; > > module_driver(ad74413r_driver,
On 12/11/2022 17.50, Jonathan Cameron wrote: > On Fri, 11 Nov 2022 15:39:17 +0100 > Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote: > >> Silence the run-time warning >> >> SPI driver ad74413r has no spi_device_id for adi,ad74412r >> >> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> >> --- >> drivers/iio/addac/ad74413r.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c >> index 899bcd83f40b..37485be88a63 100644 >> --- a/drivers/iio/addac/ad74413r.c >> +++ b/drivers/iio/addac/ad74413r.c >> @@ -1457,12 +1457,20 @@ static const struct of_device_id ad74413r_dt_id[] = { >> }; >> MODULE_DEVICE_TABLE(of, ad74413r_dt_id); >> >> +static const struct spi_device_id ad74413r_spi_id[] = { >> + { .name = "ad74412r", .driver_data = (kernel_ulong_t)&ad74412r_chip_info_data }, >> + { .name = "ad74413r", .driver_data = (kernel_ulong_t)&ad74413r_chip_info_data }, >> + {}, > Trivial, but prefer not to have a comma after a "NULL" terminator like this. > It would never make sense to add anything after it in the array. I agree and wouldn't have added it if it weren't for the existing case in the other table. > Now you are matching existing driver style, but I'd still rather not see more > instances of this added. Sure. > Also, driver_data is not currently used. It should be because adding this > spi_id table means the driver can be probed via various routes where > device_get_match_data() == NULL. That makes sense, I think I thought that that would somehow happen automatically. Looking through the history of similar fixes, I see that for example 3f8dd0a7dc does indeed add code as you suggest, but 855fe49984 does not (and also doesn't add the corresponding .driver_data initializers in the spi table). They may very well both be correct, but looping in Oleksij for good measure. > Hence, alongside this change you need to have a fallback to cover that case. > Something along the lines of... > > st->chip_info = device_get_match_data(..); > if (!st->chip_info) { > struct spi_device_id *id = spi_get_device_id(); > if (!id) > return -EINVAL; > > st->chip_info = (void *)id->driver_data; > //or better yet cast to the correct type I'm just too lazy to look it up ;) > if (!st->chip_info) > return -EINVAL; > > } Thanks, Rasmus
On Mon, 14 Nov 2022 09:02:44 +0100 Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote: > On 12/11/2022 17.50, Jonathan Cameron wrote: > > On Fri, 11 Nov 2022 15:39:17 +0100 > > Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote: > > > >> Silence the run-time warning > >> > >> SPI driver ad74413r has no spi_device_id for adi,ad74412r > >> > >> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> > >> --- > >> drivers/iio/addac/ad74413r.c | 8 ++++++++ > >> 1 file changed, 8 insertions(+) > >> > >> diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c > >> index 899bcd83f40b..37485be88a63 100644 > >> --- a/drivers/iio/addac/ad74413r.c > >> +++ b/drivers/iio/addac/ad74413r.c > >> @@ -1457,12 +1457,20 @@ static const struct of_device_id ad74413r_dt_id[] = { > >> }; > >> MODULE_DEVICE_TABLE(of, ad74413r_dt_id); > >> > >> +static const struct spi_device_id ad74413r_spi_id[] = { > >> + { .name = "ad74412r", .driver_data = (kernel_ulong_t)&ad74412r_chip_info_data }, > >> + { .name = "ad74413r", .driver_data = (kernel_ulong_t)&ad74413r_chip_info_data }, > >> + {}, > > Trivial, but prefer not to have a comma after a "NULL" terminator like this. > > It would never make sense to add anything after it in the array. > > I agree and wouldn't have added it if it weren't for the existing case > in the other table. > > > Now you are matching existing driver style, but I'd still rather not see more > > instances of this added. > > Sure. > > > Also, driver_data is not currently used. It should be because adding this > > spi_id table means the driver can be probed via various routes where > > device_get_match_data() == NULL. > > That makes sense, I think I thought that that would somehow happen > automatically. Looking through the history of similar fixes, I see that > for example 3f8dd0a7dc does indeed add code as you suggest, but > 855fe49984 does not (and also doesn't add the corresponding .driver_data > initializers in the spi table). They may very well both be correct, but > looping in Oleksij for good measure. It depends a bit on whether there is any plausible chance of anyone making use of say greybus with the device (I think that still relies on the spi id though not checked recently). If not and no board files exist, chances are that all is needed is the id table (to make autoprobing of modules work). Still I'd not leave the opening for the unexpected to happen given users have an annoying habit of finding the corner cases :) Jonathan > > > Hence, alongside this change you need to have a fallback to cover that case. > > Something along the lines of... > > > > st->chip_info = device_get_match_data(..); > > if (!st->chip_info) { > > struct spi_device_id *id = spi_get_device_id(); > > if (!id) > > return -EINVAL; > > > > st->chip_info = (void *)id->driver_data; > > //or better yet cast to the correct type I'm just too lazy to look it up ;) > > if (!st->chip_info) > > return -EINVAL; > > > > } > > Thanks, > Rasmus >
diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index 899bcd83f40b..37485be88a63 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -1457,12 +1457,20 @@ static const struct of_device_id ad74413r_dt_id[] = { }; MODULE_DEVICE_TABLE(of, ad74413r_dt_id); +static const struct spi_device_id ad74413r_spi_id[] = { + { .name = "ad74412r", .driver_data = (kernel_ulong_t)&ad74412r_chip_info_data }, + { .name = "ad74413r", .driver_data = (kernel_ulong_t)&ad74413r_chip_info_data }, + {}, +}; +MODULE_DEVICE_TABLE(spi, ad74413r_spi_id); + static struct spi_driver ad74413r_driver = { .driver = { .name = "ad74413r", .of_match_table = ad74413r_dt_id, }, .probe = ad74413r_probe, + .id_table = ad74413r_spi_id, }; module_driver(ad74413r_driver,