Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6254279iob; Tue, 10 May 2022 14:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq55aUNfQ8xa3bCi0SpwoEktm1Av3qOplrrTwQPQVTJcR6pIxQQauKaWHJHR4ZvDSMKqI2 X-Received: by 2002:a05:6402:40d4:b0:427:de1e:6ce0 with SMTP id z20-20020a05640240d400b00427de1e6ce0mr25420875edb.227.1652216695711; Tue, 10 May 2022 14:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652216695; cv=none; d=google.com; s=arc-20160816; b=EdemSC84hFHlzP3cnqy4ENe6sXY9zeU8WgzTJl3khWM/IQApdgw0x4/4EyQtLLM9p2 ZlkOcSLR9imaz4WsptOqmxydcY3SvIQurjp27ET2ceuZw4KbF1a/YLDNhd6+iSbrrpZl t08mr6ExSfAECV4R/LJuMgzuf9/ep+Yt9qhPqnFFMQ4KpY3gEaeZa9yokiGe02kc5HOL GKppD4qNvLuokMf31nKMNzsgN4Fbs3zJDXeTyz+xXREF6lXDmn9FS8cIuu3RAMALV5WI 0/jjH+3FK0LvPyujiK5xNSsmCsFYS5FdD+fopBDethDcyr98CEXJVzdpRvN8KUoKp9LR mjSw== 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=viS4Yn9JNU9a7uInv7JUdd8B1Vi/g3C3ZVyiEeR+yA4=; b=aSDTXlsTjpaWEho1MY6xyFRfQ27xVgMefADdlhsHP0fGXQVW0wR41YIoZiJy3bZBwF j7Fcj33sgK9ufdNGsgOusoLU3vZVv2rGGZP/LuWdoZSrM0Eyw1AviPtiL1tvID1v1m9k F3hNQD1wKoiuUoLHdZ8j4P17A//pPock5MURYsUi7sjpBHLUhUMHCXt3psAXUSqaXXXV iOlO6QLmw61ts2mQk7ROBgZctCLZGTfACT7+FkSv+s++3NOuo9NMbsuFAUP559YO9wh9 2bMSuL6ZkSNDFJPnYkwDUud3Y1ELi2J8Uf3kZJ46/xJzfpYDNM+cBNsozqTKCufUY7BF 0xrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z1YKrKLZ; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp16-20020a170906c15000b006f37a0e4737si351110ejc.381.2022.05.10.14.04.28; Tue, 10 May 2022 14:04:55 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=z1YKrKLZ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239808AbiEJNw6 (ORCPT + 99 others); Tue, 10 May 2022 09:52:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243799AbiEJNgI (ORCPT ); Tue, 10 May 2022 09:36:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 649052D4B64; Tue, 10 May 2022 06:25:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id 4679DB81DAB; Tue, 10 May 2022 13:25:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FC2BC385A6; Tue, 10 May 2022 13:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189105; bh=Ug3tQ3QO9GG6qpH5Bj4AlY9aW8ATwK3bWbZmf6APSNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z1YKrKLZLFSV0EYWwYQmWGh8I2ytZPgFfhQ2nkjoRXMid3NKs5xuW+iBI9C6ynpvm xa91gihxzORapvgDftU/kl1raZq11Ljc2YeX61oPPMPieRMy0EOFBotawFss+1S91+ Glxr52q8G/hwzeOfKbERbn8hWj5Wmmf2kUcudonw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niels Dossche , Takashi Sakamoto , Takashi Iwai Subject: [PATCH 5.10 14/70] firewire: core: extend card->lock in fw_core_handle_bus_reset Date: Tue, 10 May 2022 15:07:33 +0200 Message-Id: <20220510130733.285085693@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.861729621@linuxfoundation.org> References: <20220510130732.861729621@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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: Niels Dossche commit a7ecbe92b9243edbe94772f6f2c854e4142a3345 upstream. card->local_node and card->bm_retries are both always accessed under card->lock. fw_core_handle_bus_reset has a check whose condition depends on card->local_node and whose body writes to card->bm_retries. Both of these accesses are not under card->lock. Move the lock acquiring of card->lock to before this check such that these accesses do happen when card->lock is held. fw_destroy_nodes is called inside the check. Since fw_destroy_nodes already acquires card->lock inside its function body, move this out to the callsites of fw_destroy_nodes. Also add a comment to indicate which locking is necessary when calling fw_destroy_nodes. Cc: Signed-off-by: Niels Dossche Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20220409041243.603210-4-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- drivers/firewire/core-card.c | 3 +++ drivers/firewire/core-topology.c | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -668,6 +668,7 @@ EXPORT_SYMBOL_GPL(fw_card_release); void fw_core_remove_card(struct fw_card *card) { struct fw_card_driver dummy_driver = dummy_driver_template; + unsigned long flags; card->driver->update_phy_reg(card, 4, PHY_LINK_ACTIVE | PHY_CONTENDER, 0); @@ -682,7 +683,9 @@ void fw_core_remove_card(struct fw_card dummy_driver.stop_iso = card->driver->stop_iso; card->driver = &dummy_driver; + spin_lock_irqsave(&card->lock, flags); fw_destroy_nodes(card); + spin_unlock_irqrestore(&card->lock, flags); /* Wait for all users, especially device workqueue jobs, to finish. */ fw_card_put(card); --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -374,16 +374,13 @@ static void report_found_node(struct fw_ card->bm_retries = 0; } +/* Must be called with card->lock held */ void fw_destroy_nodes(struct fw_card *card) { - unsigned long flags; - - spin_lock_irqsave(&card->lock, flags); card->color++; if (card->local_node != NULL) for_each_fw_node(card, card->local_node, report_lost_node); card->local_node = NULL; - spin_unlock_irqrestore(&card->lock, flags); } static void move_tree(struct fw_node *node0, struct fw_node *node1, int port) @@ -509,6 +506,8 @@ void fw_core_handle_bus_reset(struct fw_ struct fw_node *local_node; unsigned long flags; + spin_lock_irqsave(&card->lock, flags); + /* * If the selfID buffer is not the immediate successor of the * previously processed one, we cannot reliably compare the @@ -520,8 +519,6 @@ void fw_core_handle_bus_reset(struct fw_ card->bm_retries = 0; } - spin_lock_irqsave(&card->lock, flags); - card->broadcast_channel_allocated = card->broadcast_channel_auto_allocated; card->node_id = node_id; /*