Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2194943iof; Tue, 7 Jun 2022 22:50:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNkaN8r3gGeJddRTcqlBrQAs2ZwXpMhasXs14p83T9hXNkg1+8veAcCgu4v5/WIHMZsix7 X-Received: by 2002:aa7:8d47:0:b0:4f6:a7f9:1ead with SMTP id s7-20020aa78d47000000b004f6a7f91eadmr32788673pfe.42.1654667430936; Tue, 07 Jun 2022 22:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667430; cv=none; d=google.com; s=arc-20160816; b=qiH7grvl8ap5wCDEoaPtAHvBLvKVlifUUvn9Qi7MBvlhCivMZGuvigFUsHnDRWSEAj etuxkWiU8JjgRIshFdRWdIN/Av4+mkVIwzKA4n9uHRkX2Hw19CXqi1BR0zxFGlN96vnC mbQS7Lxa6Xg7lrOlW25YJrMfT3hrlcP8cAbUku+nCnwCMikFzgf2bw84fobTF2gNDUmW CHJqBnwP0r9N9raLq4QrP5kdU6dZ0mKfKw7ls9aP/h++AwscpYC57cJn9nEuZ9mjLQye crurPwRuW/EIPcv+G+eoaFN2c7ilWve4qZBGvYiCMStyDmEVU5A2SsGsblFwX8ZuS+9N MdJw== 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=nPLP9LwKnEwH9ogbCDHAU43FtBU2SuxJ52jtCJ0QAAg=; b=CfAahCc32vJOGKUEuAsU32Rx9qEB5VhHODMpM3aajh9st5T8O3AeUq5jm3cV0zM1Jf JJh4UF3vcBwS8I2hCVenn6reKj1UaP3lWHN4cBxVoR7ML09qydHbQ/h1IqKsjDxSV0/y E92BwiZdfUz5WTesPKJTh1Vm9NxolK4gwxt1bxdapXak9H5BAVYSz5+uVG7Ct8E6TMAO I2QKrUyTW9rAnKRAH4AaSYvLsmbyTsLjqg5SuANqQjm8Zpmb+CD1C5CdIsuiN5yoaO/m GkqR+SI3iuHgoXEnnfYjqSvrqwSH3uAB1t12ewEbj7TV3X/SvDW2dmvett3SHHkdoeeP hwfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=esiKlsUI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u15-20020a170903124f00b0016382c70069si2725373plh.150.2022.06.07.22.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=esiKlsUI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 5DF272067B7; Tue, 7 Jun 2022 22:17:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350224AbiFHAoG (ORCPT + 99 others); Tue, 7 Jun 2022 20:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385612AbiFGWbk (ORCPT ); Tue, 7 Jun 2022 18:31:40 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77E8427B4B2; Tue, 7 Jun 2022 12:25:05 -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 sin.source.kernel.org (Postfix) with ESMTPS id BD1EFCE24B5; Tue, 7 Jun 2022 19:25:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C655C385A2; Tue, 7 Jun 2022 19:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629901; bh=rwjEMce8YE7+lD9mvybKKRrz9QnjWh880W853j6rDnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=esiKlsUIeLz7MFOj/BxvqzxCX3+8UVu7dWEuKx4ccldKXcGn2cNytE6K8d1+owPEq wqigJRbjATmm8lF10jBJYvul0wyGWk7315emw+HZM95Sw5W6HIjoSMMVAviFesc2yC mGw86kBqllTBmC1yjPxfmcGq0rzGTGw4mYYv/I7w= 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.18 859/879] coresight: core: Fix coresight device probe failure issue Date: Tue, 7 Jun 2022 19:06:17 +0200 Message-Id: <20220607165027.788722837@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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 @@ -1379,7 +1379,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) @@ -1571,6 +1571,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) { @@ -1591,7 +1592,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; @@ -1616,6 +1618,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); @@ -1623,7 +1632,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 || @@ -1638,11 +1647,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) @@ -1652,16 +1661,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);