Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3886850pxm; Tue, 1 Mar 2022 07:16:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAuYjwUcRqHeDyuGQbNaMOmG7DMNgpzUVTYc8QAVtTYSaQ9lk98MljUuNIEGX48KU7WZ9a X-Received: by 2002:a17:906:6d04:b0:6d6:e280:2e47 with SMTP id m4-20020a1709066d0400b006d6e2802e47mr3612646ejr.50.1646147814509; Tue, 01 Mar 2022 07:16:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646147814; cv=none; d=google.com; s=arc-20160816; b=LwxBtWiDoavQQIBqJO414Y2T1rvExGq+HWqZW4QghJU1dQesqZoOJB8uUg/FkHGo1Y VAByA6izQmACipKXXGrctRYXUQUHDgr9ZBMXdH4OLOaFDkyts/m6jvVBHk9hp3ZWEuhj +0r0agYbv9f2FC/epVeGwTvMNdp3q7Ri97W06nHP3kzvV3/QaLA52YL+m509oNT4KE22 ckqOll8umnbPfoq23aFzV542437SJjh4Jpl33VPyioQIGCpjOX47D63NQnB+CxU4KSRf iCCMJ/AmWYhgfpayj6ZjsyE3T5wJ5hEPlkLl94LFkyoQoPJG1c6LKR5NbFdexELO6L5h HlCw== 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=MjO7LQUfAS3drds+Q1SslmANfBM+W2CvtJ6vxLoq5OU=; b=lQcBhkFwksLF48Da8ViuHVBqPVF9n562DqlWlHv1w/zaZxqXXGvmMvWY0Hw14OqT7a rtu6Z5Qrovcz6sL+HDgRRTGBpRfR13b+NV7Rdswqge69+jryIGc8vjeqTJrByDVYNO+r 0Zcf4dGnr1pzMxPOa1ULWG2OmM/q9N0xYezat6r2mU0T3zz9x0m9/RgzA7iK6fwF4ud7 QGWeexvPCJJKJ4atoiAulnyztNt7Sm5R/HzZEOs58QcxMxygvMjK6mjzm/vvjq4Uprvl uUMI1mwZJcLAfrpYgamzqCW4R+7l2nIy0a0pSQ2pJ0L/iIy8k8JF0wkFJ7RJOB5PfQk8 grFA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a17090665c400b006d5fd6aa137si8178070ejn.607.2022.03.01.07.16.30; Tue, 01 Mar 2022 07:16:54 -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; 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 S234453AbiCALLZ (ORCPT + 99 others); Tue, 1 Mar 2022 06:11:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233165AbiCALLX (ORCPT ); Tue, 1 Mar 2022 06:11:23 -0500 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE3357492 for ; Tue, 1 Mar 2022 03:10:40 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:d19a:1d86:8408:fe96]) by laurent.telenet-ops.be with bizsmtp id 0zAd2704K2dyv6m01zAdTt; Tue, 01 Mar 2022 12:10:38 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nP0Or-002KSx-BH; Tue, 01 Mar 2022 12:10:37 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nP0Oq-006QpQ-Kp; Tue, 01 Mar 2022 12:10:36 +0100 From: Geert Uytterhoeven To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Arnd Bergmann , Lee Jones Cc: linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] base: soc: Make soc_device_match() simpler and easier to read Date: Tue, 1 Mar 2022 12:10:35 +0100 Message-Id: <9f9107c06f7d065ae6581e5290ef5d72f7298fd1.1646132835.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org The function soc_device_match() is difficult to read for various reasons: - There are two loop conditions using different styles: "while (...)" (which is BTW always true) vs. "if ... break", - The are two return condition using different logic: "if ... return foo" vs. "if ... else return bar". Make the code easier to read by: 1. Removing the always-true "!ret" loop condition, and dropping the now unneeded pre-initialization of "ret", 2. Converting "if ... break" to a proper "while (...)" loop condition, 3. Inverting the logic of the second return condition. Signed-off-by: Geert Uytterhoeven --- drivers/base/soc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/base/soc.c b/drivers/base/soc.c index 0af5363a582c36dd..22130b5f789d9d7e 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -241,15 +241,13 @@ static int soc_device_match_one(struct device *dev, void *arg) const struct soc_device_attribute *soc_device_match( const struct soc_device_attribute *matches) { - int ret = 0; + int ret; if (!matches) return NULL; - while (!ret) { - if (!(matches->machine || matches->family || - matches->revision || matches->soc_id)) - break; + while (matches->machine || matches->family || matches->revision || + matches->soc_id) { ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches, soc_device_match_one); if (ret < 0 && early_soc_dev_attr) @@ -257,10 +255,10 @@ const struct soc_device_attribute *soc_device_match( matches); if (ret < 0) return NULL; - if (!ret) - matches++; - else + if (ret) return matches; + + matches++; } return NULL; } -- 2.25.1