Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1716271pxp; Mon, 7 Mar 2022 00:23:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxPCR2KL+KyqxgnxGnN3wGEuwZ4bHwe3X4emClX5QqtYq7LG1pOyFtSIY76ZjWGgPh/yzl X-Received: by 2002:a17:90b:4d0c:b0:1bf:46b7:dc96 with SMTP id mw12-20020a17090b4d0c00b001bf46b7dc96mr9071310pjb.80.1646641414826; Mon, 07 Mar 2022 00:23:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646641414; cv=none; d=google.com; s=arc-20160816; b=XlYtms7gB2gqh4gXgEaPu9bjhF3GkcBYBBmD+XYdDB1PXrwki82gI3dbfBziGsDCw4 zDtQAru8wCo6KpJL4TMiSE8HAZXr6JQcGrNvMZGNOu47K1HTUNbxCB8QWQwkBqAQYD2L 6EX+lk1znewe8XrijoLIkWfo7QxpvCJ1ZFix0nz2nfiP2DyydA774Wg9G7Q2uhFeful8 mZX4R6NSt11L8pPKaSAEjLA4VHlnbohAeCrktjgd2tVZnYpo1S6QAlks4m1Y133En11f k7yI7jSy2PhmF15CKBvXr+1umYuqGQ99/CNNU8q6Rhm+2dvFLvPOLLPgpU07i2hYli6q O3PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NrL2GbvVpGb29Fj3Rihhmr0iZS/oGZ6Whqfe0P71jDo=; b=Nf0zseoxHo3Cy9rh8g9RMhMkUuhDKmWN88ujW8SmZjGRUXwC7QMpp069Wx9tBquxNA 6nBjFTlIaqERp/oAIWp1G9aAh3DEQStZcb4ypbMkL7n/lxO0qHu+QxLEIXqNsqJsUPkJ rgb1wIs5H561Gl14pbgf9JynlXnXlqB8W5lRbviB+zAcxTL1KuJ9z0vbVaHyCRTQivlJ G+uOzS9IRBJAkZGNvNtHq6nO/x07K2rD6b7cFMdmZAWAhLl4khjEbvddRzcYG8KeVXjT 3vHLp4YCZ7dRbQ2oBJKmGiT3VhxgTn5iO/OCs1c3WrqcCwhBnT/mRsBKs9EH9w0qjGJt V0tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HoesBsDj; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c2-20020a655a82000000b003632fc0b6c0si11780134pgt.744.2022.03.07.00.23.18; Mon, 07 Mar 2022 00:23:34 -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=@linaro.org header.s=google header.b=HoesBsDj; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234942AbiCGDKF (ORCPT + 99 others); Sun, 6 Mar 2022 22:10:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232049AbiCGDKE (ORCPT ); Sun, 6 Mar 2022 22:10:04 -0500 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A5E36151 for ; Sun, 6 Mar 2022 19:09:09 -0800 (PST) Received: by mail-oi1-x234.google.com with SMTP id n7so4109455oif.5 for ; Sun, 06 Mar 2022 19:09:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NrL2GbvVpGb29Fj3Rihhmr0iZS/oGZ6Whqfe0P71jDo=; b=HoesBsDjd7+aEljMQq6FmZvxEOTUGHpDp9Txbuo/3IREDz2j65Zk/VnVT2GZ4r/JAp vXTCstmbhU0Ko1SGrhRrz90k40tiiknNeMUT9RgwiBYQGCzm21ceF8zoxFlA9MKwZjc1 bQFJKk7m+DTTOuTeNlE4lfnzZvD5RL8+ENgB9UiHQUPfZv7bYffRTtDPUgxsPTNpHKS+ gwS0KyBFefrVs9BlDf90ZtDYy2s58YFIF77DRb7g5kOvFmydWLvmAODkc790wxbOuwrr sS7/Oe9H3Yt4SGWrKgZDWu1ybef3RG8OUsQTdiDEeLsx4NzY8i27oBrxLImFevcvF4At IgBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NrL2GbvVpGb29Fj3Rihhmr0iZS/oGZ6Whqfe0P71jDo=; b=SRzKgoSVldwE4Jk0DdLLP1Fb+QlN7Ynr3ngCe6yUvxYGMS8PPQrryytX556B0ojh9l POfvEpb5RIMz7u02CgUgqadq8bymn4S8T6mGJ8IgFAm9mfUYjdG5XtajFDm5+PSf1b3j 91ZaFdVht9kaaLy0D3TugpsAxmZH59XH+VH2iLrmP0rVN0RnzBllZeKuM7crPMBm4aRj CDlKz4WQMgpQXAbJQiMKHOOXFH2WlWUYLWoJOZ/KxH4TdUsLZM/q2XvY2p8mqi7pw+k0 7S4Dt5Jh8izIpELh6lYJ6N9HMdWFizm6vuq6ETPPPwNT04cRMyJWnyKSnCiv/s45JjIp DWTg== X-Gm-Message-State: AOAM532S15CFBAQpG1fL7ZlVOn7B7/XjH6IawiUSPRTQI7LCkbhTgF9f cthS4uEnd6CWQeFs9GyxeDLyHBMwTcAwnQ== X-Received: by 2002:a05:6808:152c:b0:2d7:58b0:15b9 with SMTP id u44-20020a056808152c00b002d758b015b9mr5727574oiw.81.1646622548343; Sun, 06 Mar 2022 19:09:08 -0800 (PST) Received: from yoga ([2600:1700:a0:3dc8:5c39:baff:fe03:898d]) by smtp.gmail.com with ESMTPSA id q62-20020a4a3341000000b00320f8a179d0sm439197ooq.30.2022.03.06.19.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 19:09:07 -0800 (PST) Date: Sun, 6 Mar 2022 21:09:05 -0600 From: Bjorn Andersson To: Andy Shevchenko Cc: Rob Herring , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Hans de Goede , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Dmitry Baryshkov Subject: Re: [PATCH v3 4/6] typec: mux: Allow multiple mux_devs per mux Message-ID: References: <20220303223351.141238-1-bjorn.andersson@linaro.org> <20220303223351.141238-4-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 04 Mar 07:54 CST 2022, Andy Shevchenko wrote: > On Thu, Mar 03, 2022 at 02:33:49PM -0800, Bjorn Andersson wrote: > > In the Qualcomm platforms the USB/DP PHY handles muxing and orientation > > switching of the SuperSpeed lines, but the SBU lines needs to be > > connected and switched by external (to the SoC) hardware. > > > > It's therefor necessary to be able to have the TypeC controller operate > > multiple TypeC muxes and switches. Use the newly introduced indirection > > object to handle this, to avoid having to taint the TypeC controllers > > with knowledge about the downstream hardware configuration. > > > > The max number of devs per indirection is set to 3, which account for > > being able to mux/switch the USB HS, SS and SBU lines, as per defined > > defined in the usb-c-connector binding. This number could be grown if > > need arrises at a later point in time. > > ... > > > + for (i = 0; i < count; i++) { > > + if (IS_ERR(sw_devs[i])) { > > + err = PTR_ERR(sw_devs[i]); > > + goto put_sw_devs; > > + } > > + } > > > > - sw->sw_dev = sw_dev; > > + for (i = 0; i < count; i++) { > > + WARN_ON(!try_module_get(sw_devs[i]->dev.parent->driver->owner)); > > + sw->sw_devs[i] = sw_devs[i]; > > + } > > + > > + sw->num_sw_devs = count; > > > > return sw; > > + > > +put_sw_devs: > > + for (i = 0; i < count; i++) { > > Shouldn't it be > > while (i--) > > ? fwnode_connection_find_matches() "returned" count number of sw_devs, we need to put_device() them all. So that form could have been while (count--) but as it's not the typical "unrolling" I think the untypical form is more useful. > > > + if (!IS_ERR(sw_devs[i])) > > We may get rid of this check if we guarantee that the device is NULL. > In the event that the USB Type-C controller probes before some of the muxes, this array might contain one or more entries of EPROBE_DEFER. So we need to either put this conditional here, or we need to loop through all entries to turn IS_ERR() into NULL, for the sake of not having it here. So to me this looks cleaner... Regards, Bjorn > > + put_device(&sw_devs[i]->dev); > > + } > > + > > + kfree(sw); > > + > > + return ERR_PTR(err); > > } > > ... > > > + for (i = 0; i < count; i++) { > > + if (IS_ERR(mux_devs[i])) { > > + err = PTR_ERR(mux_devs[i]); > > + goto put_mux_devs; > > + } > > Ditto. > > > + } > > ... > > > +put_mux_devs: > > + for (i = 0; i < count; i++) { > > + if (!IS_ERR(mux_devs[i])) > > + put_device(&mux_devs[i]->dev); > > + } > > Ditto. > > -- > With Best Regards, > Andy Shevchenko > >