From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC3CAC433C1 for ; Wed, 24 Mar 2021 15:33:56 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 012BD61962 for ; Wed, 24 Mar 2021 15:33:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 012BD61962 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 3AAAF16A5; Wed, 24 Mar 2021 16:33:04 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3AAAF16A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1616600034; bh=Wlgz++fQTKYVsteeIn806tWJROYW5jiPnR2mdLDUZGI=; h=Subject:To:References:From:Date:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LUoOndbJYOZNKjETkQn840AVWhnKHN6CUxCTGledKKfSKVCrWknRkacejffUfPvu7 5xeR8YibHz8Fem2UWzIxYD7txexocrioc8bdTJ1QZdBIL/8h+veEo7N3tiZgH/8vOm wXf3j7V3hPefo0J20dQYPssZDWTIEdDxhoVCVeEg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id ACB60F801EB; Wed, 24 Mar 2021 16:32:13 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 457AEF8016B; Wed, 24 Mar 2021 16:32:11 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 1BB89F80104 for ; Wed, 24 Mar 2021 16:32:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1BB89F80104 IronPort-SDR: 0UMgdIFyCbiHyz7FEnfZfrjXYLEGdQUwJzQD23iQS+rdfCCfiafqJ99G3wKdiVX2kOLDmC7KfE UCg8GfWUjqzw== X-IronPort-AV: E=McAfee;i="6000,8403,9933"; a="188427852" X-IronPort-AV: E=Sophos;i="5.81,275,1610438400"; d="scan'208";a="188427852" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2021 08:31:59 -0700 IronPort-SDR: KvDCAb661kRGCW3L7DcBK0x4sJ9Z947z1JgdkPE/knlly8SVix+WP2nrSKT0N8y1p1ErDT4s3i lw4TePEghKPA== X-IronPort-AV: E=Sophos;i="5.81,275,1610438400"; d="scan'208";a="608143679" Received: from mailunda-mobl.amr.corp.intel.com (HELO [10.209.33.48]) ([10.209.33.48]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2021 08:31:57 -0700 Subject: Re: [PATCH] soundwire: intel: move to auxiliary bus To: Greg KH References: <20210323004325.19727-1-yung-chuan.liao@linux.intel.com> <777b4ca6-0d51-285d-549f-6ef768f2a523@linux.intel.com> <35cc8d35-a778-d8b2-bee3-bb53f8a6c51e@linux.intel.com> From: Pierre-Louis Bossart Message-ID: <357d9576-f79a-0ea6-eee4-292e27597565@linux.intel.com> Date: Wed, 24 Mar 2021 09:55:01 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Cc: alsa-devel@alsa-project.org, vinod.koul@linaro.org, linux-kernel@vger.kernel.org, hui.wang@canonical.com, vkoul@kernel.org, srinivas.kandagatla@linaro.org, sanyog.r.kale@intel.com, Bard Liao , rander.wang@linux.intel.com, bard.liao@intel.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" >>>>>> Note that the auxiliary bus API has separate init and add steps, which >>>>>> requires more attention in the error unwinding paths. The main loop >>>>>> needs to deal with kfree() and auxiliary_device_uninit() for the >>>>>> current iteration before jumping to the common label which releases >>>>>> everything allocated in prior iterations. >>>>> >>>>> The init/add steps can be moved together in the aux bus code if that >>>>> makes this usage simpler. Please do that instead. >>>> >>>> IIRC the two steps were separated during the auxbus reviews to allow the >>>> parent to call kfree() on an init failure, and auxiliary_device_uninit() >>>> afterwards. >>>> >>>> https://www.kernel.org/doc/html/latest/driver-api/auxiliary_bus.html#auxiliary-device >>>> >>>> With a single auxbus_register(), the parent wouldn't know whether to use >>>> kfree() or auxiliary_device_uinit() when an error is returned, would it? >>>> >>> >>> It should, you know the difference when you call device_register() vs. >>> device_initialize()/device_add(), for what to do, right? >>> >>> Should be no difference here either :) >> >> sorry, not following. >> >> with the regular devices, the errors can only happen on the second "add" >> stage. >> >> int device_register(struct device *dev) >> { >> device_initialize(dev); >> return device_add(dev); >> } >> >> that's not what is currently implemented for the auxiliary bus >> >> the current flow is >> >> ldev = kzalloc(..) >> some inits >> ret = auxiliary_device_init(&ldev->auxdev) >> if (ret < 0) { >> kfree(ldev); >> goto err1; >> } >> >> ret = auxiliary_device_add(&ldev->auxdev) >> if (ret < 0) >> auxiliary_device_uninit(&ldev->auxdev) >> goto err2; >> } >> ... >> err2: >> err1: >> >> How would I convert this to >> >> ldev = kzalloc(..) >> some inits >> ret = auxiliary_device_register() >> if (ret) { >> kfree(ldev) or not? >> unit or not? >> } >> >> IIRC during reviews there was an ask that the parent and name be checked, >> and that's why the code added the two checks below: >> >> int auxiliary_device_init(struct auxiliary_device *auxdev) >> { >> struct device *dev = &auxdev->dev; >> >> if (!dev->parent) { >> pr_err("auxiliary_device has a NULL dev->parent\n"); >> return -EINVAL; >> } >> >> if (!auxdev->name) { >> pr_err("auxiliary_device has a NULL name\n"); >> return -EINVAL; >> } >> >> dev->bus = &auxiliary_bus_type; >> device_initialize(&auxdev->dev); >> return 0; >> } >> >> does this clarify the sequence? > > Yes, thanks, but I don't know the answer to your question, sorry. This > feels more complex than it should be, but I do not have the time at the > moment to look into it, sorry. > > Try getting the authors of this code to fix it up :) We can try to check why those two tests were added before initialize(), I don't fully recall these details If we could move these tests after device_initialize() then we could add a _register function. Note at this point it would mean an API change and impact the existing Nvidia/Mellanox code, we are using the same sequence as them https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/mellanox/mlx5/core/dev.c#L262