Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2293654iof; Wed, 8 Jun 2022 01:40:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/VsrFuPzWhiu8u/neb58NTz1IPBkmkvrv/Oh7H1CZNYd1iD+pdOSxneGuOlzLfUlRsiej X-Received: by 2002:a17:902:dac7:b0:166:4ce4:7e32 with SMTP id q7-20020a170902dac700b001664ce47e32mr29261675plx.168.1654677614275; Wed, 08 Jun 2022 01:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654677614; cv=none; d=google.com; s=arc-20160816; b=kYXBACuwk1oEIJXUjLzQ1Hge4ptIug557chdUTH0umP3/uFgydvU36bBulimTaBX7P Rtx8nVYWsmPzDNys789/ooUi+C1R5UEJWwG3H8slZmPDDHZLZZtszI5naKdjhb4ds3ly qdnWHwazs4NMoTeDPWcCwNHGxUaQyYdvOViK9DjSwEroCZQCVUqWwsUTn3WQDU6MJ/G/ GiU5Ybs7cLMg3u3BxP70SGgYnkaFjd8qQCxF+YJhG1gMc4SJoI6sdREf/8nPLwtT+7l7 FMFEwA+CZCs2TEa2YFdCxq7vl+M8o2TLttkiFMCdvIyuiI2MlgqqssYyTXOP6GlDKXit 1AIw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GWisrAlXLEB2KTSaK5XG8nC7BIe/2AJDG6UETUXQ6I4=; b=JKhv/+pye84yNFtvfIozi/TooVgB7XT7DmN4/rUrMNuHUX3mbKPRMEZSozQ70L10Ql 8hRQyWIg1CM0ahqhDAPrJImTxBvPZ1TNFEhHLNmBWf3o3tdhEpKLwOmb2V1Q1j6XHxPb U3gTIHUHbWsULcv3dDKw5T0BZW6Oo2LB5VtBSK3/kVkEV3m4N/T1bqWezH991Izvl1oC 3fZXL8tQJYw2aoPVtUyfhs3LmPLaJb2jNyTCQyFrX7fgSBLYkPsmSzbAHuGSKe9FQzkg lEDwLTnBiu85eT1cLzIohYTvu+CtQc2vR26qTE2Cmfft5N0rq4U/yz46vHlU09+XDXCh fGPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BG0ev77r; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 185-20020a6302c2000000b003fcae53b1f1si11700641pgc.173.2022.06.08.01.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:40:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BG0ev77r; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2BF6E1F184D; Wed, 8 Jun 2022 01:03:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349024AbiFGSLo (ORCPT + 99 others); Tue, 7 Jun 2022 14:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350071AbiFGRvv (ORCPT ); Tue, 7 Jun 2022 13:51:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5971140414; Tue, 7 Jun 2022 10:39:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ECAB16155F; Tue, 7 Jun 2022 17:39:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 042A7C385A5; Tue, 7 Jun 2022 17:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623549; bh=9ai2x4mUpTzJOgbzS743zBxcRco43rTjAJoOH+7BUvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BG0ev77rLYes8sxLNdbKrbK2Kl1UHQ2eFNr1EHwnvYU3wIEANiwcdqKhng/R6SOLt pjR7rnDkSbFb9MV8UTXNQxfcHtcQDiq0PzCwTitlFxCrABH8bDaoKHRlqBe5IbphV/ /kXnMoA8mXtU5vMBbN6fQk7CY/bGijnNIOr0iXZ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suzuki K Poulose , Mike Leach , Mao Jinlong Subject: [PATCH 5.10 426/452] coresight: core: Fix coresight device probe failure issue Date: Tue, 7 Jun 2022 19:04:43 +0200 Message-Id: <20220607164921.250038870@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 From: Mao Jinlong commit 8c1d3f79d9ca48e406b78e90e94cf09a8c076bf2 upstream. It is possibe that probe failure issue happens when the device and its child_device's probe happens at the same time. In coresight_make_links, has_conns_grp is true for parent, but has_conns_grp is false for child device as has_conns_grp is set to true in coresight_create_conns_sysfs_group. The probe of parent device will fail at this condition. Add has_conns_grp check for child device before make the links and make the process from device_register to connection_create be atomic to avoid this probe failure issue. Cc: stable@vger.kernel.org Suggested-by: Suzuki K Poulose Suggested-by: Mike Leach Signed-off-by: Mao Jinlong Link: https://lore.kernel.org/r/20220309142206.15632-1-quic_jinlmao@quicinc.com [ Added Cc stable ] Signed-off-by: Suzuki K Poulose Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/coresight/coresight-core.c | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -1337,7 +1337,7 @@ static int coresight_fixup_device_conns( continue; conn->child_dev = coresight_find_csdev_by_fwnode(conn->child_fwnode); - if (conn->child_dev) { + if (conn->child_dev && conn->child_dev->has_conns_grp) { ret = coresight_make_links(csdev, conn, conn->child_dev); if (ret) @@ -1486,6 +1486,7 @@ struct coresight_device *coresight_regis int nr_refcnts = 1; atomic_t *refcnts = NULL; struct coresight_device *csdev; + bool registered = false; csdev = kzalloc(sizeof(*csdev), GFP_KERNEL); if (!csdev) { @@ -1506,7 +1507,8 @@ struct coresight_device *coresight_regis refcnts = kcalloc(nr_refcnts, sizeof(*refcnts), GFP_KERNEL); if (!refcnts) { ret = -ENOMEM; - goto err_free_csdev; + kfree(csdev); + goto err_out; } csdev->refcnt = refcnts; @@ -1530,6 +1532,13 @@ struct coresight_device *coresight_regis csdev->dev.fwnode = fwnode_handle_get(dev_fwnode(desc->dev)); dev_set_name(&csdev->dev, "%s", desc->name); + /* + * Make sure the device registration and the connection fixup + * are synchronised, so that we don't see uninitialised devices + * on the coresight bus while trying to resolve the connections. + */ + mutex_lock(&coresight_mutex); + ret = device_register(&csdev->dev); if (ret) { put_device(&csdev->dev); @@ -1537,7 +1546,7 @@ struct coresight_device *coresight_regis * All resources are free'd explicitly via * coresight_device_release(), triggered from put_device(). */ - goto err_out; + goto out_unlock; } if (csdev->type == CORESIGHT_DEV_TYPE_SINK || @@ -1552,11 +1561,11 @@ struct coresight_device *coresight_regis * from put_device(), which is in turn called from * function device_unregister(). */ - goto err_out; + goto out_unlock; } } - - mutex_lock(&coresight_mutex); + /* Device is now registered */ + registered = true; ret = coresight_create_conns_sysfs_group(csdev); if (!ret) @@ -1566,16 +1575,18 @@ struct coresight_device *coresight_regis if (!ret && cti_assoc_ops && cti_assoc_ops->add) cti_assoc_ops->add(csdev); +out_unlock: mutex_unlock(&coresight_mutex); - if (ret) { + /* Success */ + if (!ret) + return csdev; + + /* Unregister the device if needed */ + if (registered) { coresight_unregister(csdev); return ERR_PTR(ret); } - return csdev; - -err_free_csdev: - kfree(csdev); err_out: /* Cleanup the connection information */ coresight_release_platform_data(NULL, desc->pdata);