Message ID | 20230609183044.1764951-1-robh@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1109546vqr; Fri, 9 Jun 2023 11:39:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6VhuHdkbLfuVfxx3nORIwb0lrz5sI4G9W9ewZd/b+ukmhlJ3RlCTTOfx+R4vUiDi8RxMc+ X-Received: by 2002:a05:6a00:148d:b0:662:659c:b46f with SMTP id v13-20020a056a00148d00b00662659cb46fmr2743180pfu.31.1686335983502; Fri, 09 Jun 2023 11:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686335983; cv=none; d=google.com; s=arc-20160816; b=XSz1OJJvb7iDXvrODcXM/ib35T0fs1yYpoJy7vPona/igKODvd0UykNbdcz0TGJraI OXJlf99usmM36ky2U39/FvCbH5vv1HnI7QrwcPH73htn73nDefEERtZyFeJxOpgyW1p4 O27m5Ljm3rc496/OIxL1n3G+lplRBt0lybZmZ610NDz+jTVs+kX+4nX94lbbpHWDnI0y pXYOsSjXXKVDMZdJn/xOEiag7JNkvuf6jysZ8Aw45I3xzXIwYoVB7TX8rwh74ma+1TmG cvhPgDRs2yRWcOU1bya2ZKAWz24M/b1ZUtwSN6QdN0J93b95BRJa3va+pciH8W5IXcbY LMmA== 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 :message-id:date:subject:cc:to:from; bh=xJw31UEMSDw/4lxj847WRV5dzWgZULa7uFBez8wvxto=; b=o9SpRe1KFlEvCa20IEffv1gc8yKL8RUa4Cg3lK6KNXWmHWriV4e06yXQkHkuSfTqAp KdkaX9VivoguOlq49ofosURd0jqcUtzMjteTLT/qFi8J6JmOJ0GNTsOOh8tDDSoUjbkt TQityzQnDm6aSKfIbyzXxzK5ijK9PM4uojJLjUquxleLrA6t0HIMZdmWzMlxgEKpg8gP 0ZILXrsPUK53OpJbBV0X5MpsI7Ym8muATkz1OIazqAifd6dkZP0XbH03tKyKhEt2DhuP EPpVeYi/+ihFbceBsHOBJvHLh5GJ2l8eDPbRKiTPjtrs6bsSuInVBAK01dn8kY4KXEB1 y9Wg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q27-20020a63751b000000b0053fc68bc1b6si125554pgc.42.2023.06.09.11.39.29; Fri, 09 Jun 2023 11:39:43 -0700 (PDT) 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; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjFISbB (ORCPT <rfc822;liningstudo@gmail.com> + 99 others); Fri, 9 Jun 2023 14:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbjFISa7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 9 Jun 2023 14:30:59 -0400 Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 281C93A8C; Fri, 9 Jun 2023 11:30:56 -0700 (PDT) Received: by mail-io1-f41.google.com with SMTP id ca18e2360f4ac-777b0dd72d8so86815239f.1; Fri, 09 Jun 2023 11:30:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686335455; x=1688927455; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xJw31UEMSDw/4lxj847WRV5dzWgZULa7uFBez8wvxto=; b=XRLgB/q8ZkYQ9wWg8nNexQhn0930cuuWzoHgMj6gIXnECxkymSoHsAhZaandmotfxy 4pxW1ZbLgY3/YX/M635ACp8cLFQh+XcthmqxgoX1vWAg5eVE3GmwxVkTfDQzke52HMPM 9XHMt/Unqy+5tZYO6UGBpSwq/wj8v3Ubj2JLh1T6RFBjEfWiIgIz8EU+gcyolQw2qEmo lcROd6Bxrcb3+z8kcNs1NVYathO5937sxNGlQZkBKWps1YbSobRib1YFbFSHblMiL4qo f53CqLbobe8CoSOwtGkEfhwGZBHB0i+fmArd8+8wPoT8fjX5fragSfQrOTd+mKww87Q5 ksaA== X-Gm-Message-State: AC+VfDybBu2V0k/IMDWqu386uZG3XrhSvWrIC94NLcGZMrA1oaly8Daj MZ5hLhwCkzNVoaoE19yYhRweKxP+Yg== X-Received: by 2002:a6b:dc14:0:b0:774:9c2e:4ef5 with SMTP id s20-20020a6bdc14000000b007749c2e4ef5mr2227096ioc.6.1686335455180; Fri, 09 Jun 2023 11:30:55 -0700 (PDT) Received: from robh_at_kernel.org ([64.188.179.250]) by smtp.gmail.com with ESMTPSA id f7-20020a056638118700b00420d2a27e27sm1097043jas.84.2023.06.09.11.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 11:30:54 -0700 (PDT) Received: (nullmailer pid 1765126 invoked by uid 1000); Fri, 09 Jun 2023 18:30:53 -0000 From: Rob Herring <robh@kernel.org> To: Chris Packham <chris.packham@alliedtelesis.co.nz> Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] i2c: mpc: Use of_property_read_reg() to parse "reg" Date: Fri, 9 Jun 2023 12:30:44 -0600 Message-Id: <20230609183044.1764951-1-robh@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1768251439855592298?= X-GMAIL-MSGID: =?utf-8?q?1768251439855592298?= |
Series |
i2c: mpc: Use of_property_read_reg() to parse "reg"
|
|
Commit Message
Rob Herring
June 9, 2023, 6:30 p.m. UTC
Use the recently added of_property_read_reg() helper to get the
untranslated "reg" address value.
Signed-off-by: Rob Herring <robh@kernel.org>
---
drivers/i2c/busses/i2c-mpc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
Hi Rob, On Fri, Jun 09, 2023 at 12:30:44PM -0600, Rob Herring wrote: > Use the recently added of_property_read_reg() helper to get the > untranslated "reg" address value. > > Signed-off-by: Rob Herring <robh@kernel.org> > --- > drivers/i2c/busses/i2c-mpc.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c > index cfd074ee6d54..595dce9218ad 100644 > --- a/drivers/i2c/busses/i2c-mpc.c > +++ b/drivers/i2c/busses/i2c-mpc.c > @@ -316,9 +316,10 @@ static void mpc_i2c_setup_512x(struct device_node *node, > if (node_ctrl) { > ctrl = of_iomap(node_ctrl, 0); > if (ctrl) { > + u64 addr; > /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ > - pval = of_get_property(node, "reg", NULL); > - idx = (*pval & 0xff) / 0x20; > + of_property_read_reg(node, 0, &addr, NULL); because of_property_read_reg() can return error, can we check also the error value here? Thanks, Andi > + idx = (addr & 0xff) / 0x20; > setbits32(ctrl, 1 << (24 + idx * 2)); > iounmap(ctrl); > } > -- > 2.39.2 >
On Sat, Jun 10, 2023 at 3:36 AM Andi Shyti <andi.shyti@kernel.org> wrote: > > Hi Rob, > > On Fri, Jun 09, 2023 at 12:30:44PM -0600, Rob Herring wrote: > > Use the recently added of_property_read_reg() helper to get the > > untranslated "reg" address value. > > > > Signed-off-by: Rob Herring <robh@kernel.org> > > --- > > drivers/i2c/busses/i2c-mpc.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c > > index cfd074ee6d54..595dce9218ad 100644 > > --- a/drivers/i2c/busses/i2c-mpc.c > > +++ b/drivers/i2c/busses/i2c-mpc.c > > @@ -316,9 +316,10 @@ static void mpc_i2c_setup_512x(struct device_node *node, > > if (node_ctrl) { > > ctrl = of_iomap(node_ctrl, 0); > > if (ctrl) { > > + u64 addr; > > /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ > > - pval = of_get_property(node, "reg", NULL); > > - idx = (*pval & 0xff) / 0x20; > > + of_property_read_reg(node, 0, &addr, NULL); > > because of_property_read_reg() can return error, can we check > also the error value here? Why? The old code wasn't worried about of_get_property() returning NULL on the same possible errors. If anyone is still actually using mpc512x, I don't think their DTB will have an error at this point. IOW, is improving the error handling on this really worth it? Rob
Hi Rob, On Mon, Jun 12, 2023 at 01:27:03PM -0600, Rob Herring wrote: > On Sat, Jun 10, 2023 at 3:36 AM Andi Shyti <andi.shyti@kernel.org> wrote: > > > > Hi Rob, > > > > On Fri, Jun 09, 2023 at 12:30:44PM -0600, Rob Herring wrote: > > > Use the recently added of_property_read_reg() helper to get the > > > untranslated "reg" address value. > > > > > > Signed-off-by: Rob Herring <robh@kernel.org> > > > --- > > > drivers/i2c/busses/i2c-mpc.c | 5 +++-- > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c > > > index cfd074ee6d54..595dce9218ad 100644 > > > --- a/drivers/i2c/busses/i2c-mpc.c > > > +++ b/drivers/i2c/busses/i2c-mpc.c > > > @@ -316,9 +316,10 @@ static void mpc_i2c_setup_512x(struct device_node *node, > > > if (node_ctrl) { > > > ctrl = of_iomap(node_ctrl, 0); > > > if (ctrl) { > > > + u64 addr; > > > /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ > > > - pval = of_get_property(node, "reg", NULL); > > > - idx = (*pval & 0xff) / 0x20; > > > + of_property_read_reg(node, 0, &addr, NULL); > > > > because of_property_read_reg() can return error, can we check > > also the error value here? > > Why? Because if a function can return an error, the error must be checked. Even if the property is "reg" and the binding says that it's required. Otherwise let's make those functions void. > The old code wasn't worried about of_get_property() returning > NULL on the same possible errors. Sure! Checking the error comes for free. The patch is fine as it is, mine was a little improvement I asked for. I can still ack it and add the error handling later myself :) > If anyone is still actually using > mpc512x, I don't think their DTB will have an error at this point. > IOW, is improving the error handling on this really worth it? In my view, every error needs to be checked as every error is unlikely to happen: it makes the code future proof and makes sure other components failure don't impact the normal functioning of this driver. Anyway, the patch is doing what you described and for the sole economy of this change: Acked-by: Andi Shyti <andi.shyti@kernel.org> Thank you, Andi
On Mon, Jun 12, 2023 at 3:08 PM Andi Shyti <andi.shyti@kernel.org> wrote: > > Hi Rob, > > On Mon, Jun 12, 2023 at 01:27:03PM -0600, Rob Herring wrote: > > On Sat, Jun 10, 2023 at 3:36 AM Andi Shyti <andi.shyti@kernel.org> wrote: > > > > > > Hi Rob, > > > > > > On Fri, Jun 09, 2023 at 12:30:44PM -0600, Rob Herring wrote: > > > > Use the recently added of_property_read_reg() helper to get the > > > > untranslated "reg" address value. > > > > > > > > Signed-off-by: Rob Herring <robh@kernel.org> > > > > --- > > > > drivers/i2c/busses/i2c-mpc.c | 5 +++-- > > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c > > > > index cfd074ee6d54..595dce9218ad 100644 > > > > --- a/drivers/i2c/busses/i2c-mpc.c > > > > +++ b/drivers/i2c/busses/i2c-mpc.c > > > > @@ -316,9 +316,10 @@ static void mpc_i2c_setup_512x(struct device_node *node, > > > > if (node_ctrl) { > > > > ctrl = of_iomap(node_ctrl, 0); > > > > if (ctrl) { > > > > + u64 addr; > > > > /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ > > > > - pval = of_get_property(node, "reg", NULL); > > > > - idx = (*pval & 0xff) / 0x20; > > > > + of_property_read_reg(node, 0, &addr, NULL); > > > > > > because of_property_read_reg() can return error, can we check > > > also the error value here? > > > > Why? > > Because if a function can return an error, the error must be > checked. Even if the property is "reg" and the binding says that > it's required. Otherwise let's make those functions void. Then every function should have a must_check annotation, but they don't as the function is designed to work with optional properties where we want to ignore errors. > > The old code wasn't worried about of_get_property() returning > > NULL on the same possible errors. > > Sure! Checking the error comes for free. The patch is fine as it > is, mine was a little improvement I asked for. I can still ack > it and add the error handling later myself :) > > > If anyone is still actually using > > mpc512x, I don't think their DTB will have an error at this point. > > IOW, is improving the error handling on this really worth it? > > In my view, every error needs to be checked as every error is > unlikely to happen: it makes the code future proof and makes sure > other components failure don't impact the normal functioning of > this driver. An error in this case is a bad DT. It's not the kernel's job to ensure DT is correct. If it is, then it is doing a terrible job. The reason we have dtschema is to ensure correctness. Rob
On Fri, Jun 09, 2023 at 12:30:44PM -0600, Rob Herring wrote: > Use the recently added of_property_read_reg() helper to get the > untranslated "reg" address value. > > Signed-off-by: Rob Herring <robh@kernel.org> Applied to for-next, thanks!
On Fri, Jun 09, 2023 at 12:30:44PM -0600, Rob Herring wrote: > Use the recently added of_property_read_reg() helper to get the > untranslated "reg" address value. > > Signed-off-by: Rob Herring <robh@kernel.org> This patch results in: Building powerpc:ppc32_allmodconfig ... failed -------------- Error log: drivers/i2c/busses/i2c-mpc.c: In function 'mpc_i2c_setup_512x': drivers/i2c/busses/i2c-mpc.c:310:20: error: unused variable 'pval' [-Werror=unused-variable] 310 | const u32 *pval; because pval is no longer used. Guenter > --- > drivers/i2c/busses/i2c-mpc.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c > index cfd074ee6d54..595dce9218ad 100644 > --- a/drivers/i2c/busses/i2c-mpc.c > +++ b/drivers/i2c/busses/i2c-mpc.c > @@ -316,9 +316,10 @@ static void mpc_i2c_setup_512x(struct device_node *node, > if (node_ctrl) { > ctrl = of_iomap(node_ctrl, 0); > if (ctrl) { > + u64 addr; > /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ > - pval = of_get_property(node, "reg", NULL); > - idx = (*pval & 0xff) / 0x20; > + of_property_read_reg(node, 0, &addr, NULL); > + idx = (addr & 0xff) / 0x20; > setbits32(ctrl, 1 << (24 + idx * 2)); > iounmap(ctrl); > } > -- > 2.39.2 >
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index cfd074ee6d54..595dce9218ad 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c @@ -316,9 +316,10 @@ static void mpc_i2c_setup_512x(struct device_node *node, if (node_ctrl) { ctrl = of_iomap(node_ctrl, 0); if (ctrl) { + u64 addr; /* Interrupt enable bits for i2c-0/1/2: bit 24/26/28 */ - pval = of_get_property(node, "reg", NULL); - idx = (*pval & 0xff) / 0x20; + of_property_read_reg(node, 0, &addr, NULL); + idx = (addr & 0xff) / 0x20; setbits32(ctrl, 1 << (24 + idx * 2)); iounmap(ctrl); }