From owner-svn-src-head@freebsd.org Wed Jan 8 23:03:48 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4D0091FE062; Wed, 8 Jan 2020 23:03:48 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47tPtr1CkYz4HPB; Wed, 8 Jan 2020 23:03:48 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 24F0C1F767; Wed, 8 Jan 2020 23:03:48 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 008N3mCS079558; Wed, 8 Jan 2020 23:03:48 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 008N3mvh079557; Wed, 8 Jan 2020 23:03:48 GMT (envelope-from ian@FreeBSD.org) Message-Id: <202001082303.008N3mvh079557@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Wed, 8 Jan 2020 23:03:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356525 - head/sys/dev/iicbus/mux X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/dev/iicbus/mux X-SVN-Commit-Revision: 356525 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jan 2020 23:03:48 -0000 Author: ian Date: Wed Jan 8 23:03:47 2020 New Revision: 356525 URL: https://svnweb.freebsd.org/changeset/base/356525 Log: Split the code to find and add iicbus children out to its own function. Move the decision to take an early exit from that function after adding children based on FDT data into the #ifdef FDT block, so that it doesn't offend coverity's notion of how the code should be written. (What's the point of compilers optimizing away dead code if static analyzers won't let you use the feature in conjuction with an #ifdef block?) Reported by: coverity via vangyzen@ Modified: head/sys/dev/iicbus/mux/iicmux.c Modified: head/sys/dev/iicbus/mux/iicmux.c ============================================================================== --- head/sys/dev/iicbus/mux/iicmux.c Wed Jan 8 22:59:31 2020 (r356524) +++ head/sys/dev/iicbus/mux/iicmux.c Wed Jan 8 23:03:47 2020 (r356525) @@ -240,36 +240,13 @@ iicmux_add_child(device_t dev, device_t child, int bus return (0); } -int -iicmux_attach(device_t dev, device_t busdev, int numbuses) +static int +iicmux_attach_children(struct iicmux_softc *sc) { - struct iicmux_softc *sc = device_get_softc(dev); - int i, numadded; - - if (numbuses >= IICMUX_MAX_BUSES) { - device_printf(dev, "iicmux_attach: numbuses %d > max %d\n", - numbuses, IICMUX_MAX_BUSES); - return (EINVAL); - } - - sc->dev = dev; - sc->busdev = busdev; - sc->maxbus = -1; - sc->numbuses = numbuses; - - SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev), - SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO, - "debugmux", CTLFLAG_RWTUN, &sc->debugmux, 0, "debug mux operations"); - - /* - * Add children... - */ - numadded = 0; - + int i; #ifdef FDT phandle_t child, node, parent; - pcell_t reg; - int idx; + pcell_t idx; /* * Find our FDT node. Child nodes within our node will become our @@ -292,14 +269,13 @@ iicmux_attach(device_t dev, device_t busdev, int numbu * Attach the children represented in the device tree. */ for (child = OF_child(parent); child != 0; child = OF_peer(child)) { - if (OF_getencprop(child, "reg", ®, sizeof(reg)) == -1) { - device_printf(dev, + if (OF_getencprop(child, "reg", &idx, sizeof(idx)) == -1) { + device_printf(sc->dev, "child bus missing required 'reg' property\n"); continue; } - idx = (int)reg; if (idx >= sc->numbuses) { - device_printf(dev, + device_printf(sc->dev, "child bus 'reg' property %d exceeds the number " "of buses supported by the device (%d)\n", idx, sc->numbuses); @@ -309,21 +285,48 @@ iicmux_attach(device_t dev, device_t busdev, int numbu sc->childnodes[idx] = child; if (sc->maxbus < idx) sc->maxbus = idx; - ++numadded; } + + /* If we configured anything using FDT data, we're done. */ + if (sc->maxbus >= 0) + return (0); #endif /* FDT */ /* - * If we configured anything using FDT data, we're done. Otherwise add - * an iicbus child for every downstream bus supported by the mux chip. + * If we make it to here, we didn't add any children based on FDT data. + * Add an iicbus child for every downstream bus supported by the mux. */ - if (numadded > 0) - return (0); - for (i = 0; i < sc->numbuses; ++i) { sc->childdevs[i] = device_add_child(sc->dev, "iicbus", -1); + sc->maxbus = i; } - sc->maxbus = sc->numbuses - 1; + + return (0); +} + +int +iicmux_attach(device_t dev, device_t busdev, int numbuses) +{ + struct iicmux_softc *sc = device_get_softc(dev); + int err; + + if (numbuses >= IICMUX_MAX_BUSES) { + device_printf(dev, "iicmux_attach: numbuses %d > max %d\n", + numbuses, IICMUX_MAX_BUSES); + return (EINVAL); + } + + sc->dev = dev; + sc->busdev = busdev; + sc->maxbus = -1; + sc->numbuses = numbuses; + + if ((err = iicmux_attach_children(sc)) != 0) + return (err); + + SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO, + "debugmux", CTLFLAG_RWTUN, &sc->debugmux, 0, "debug mux operations"); return (0); }