Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2754250pxj; Mon, 31 May 2021 09:54:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQp6yFljIJFcgRKVi+es9e3/wVqm1gZ/+6eoyVIqJy2N5pavQS38YFf/OX4eXmhdiJ2B5P X-Received: by 2002:a05:6402:368:: with SMTP id s8mr11127087edw.129.1622480085364; Mon, 31 May 2021 09:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622480085; cv=none; d=google.com; s=arc-20160816; b=KFIsUgdbSpUef+fvdFgFE2R4ZQyg7b0YqB4XSt3cTBCkggUSqqwDgEUKB1Z8XZzbY5 /MUqHYDfr/lAzL9ZvP6yEpfJvdrhTBzjTs1/htj77pWjvVFVxK18DC1DZeMeDlV3hX+z X0P+N7qhlpKUTAj5f9a91GPqosM0Coa+WzB2lLCoNN0Y8fcnYPfkS+joRmUTC/dpPpUh nOuJoWISKPnHqHmJ4rSEiCgsfqhgMjp28Q4JI1SWLVA9xNs+y5VZSU5OHGIJ1R1daPWf 73NMMXB2hSqAiWFZdm+IZnoPkK1UBI+cID0aezP9YONzQDlA5eIueRGvEfk3opZG11Y2 LZZg== 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=bkkDOwIpwn1tZSFmUTbgT1O264uBNDV3IY1lDGwgy7M=; b=KDetCgkb8KltjhaUVHTcAkEagZnuaIU7qHN3fCp5wCAlfSMkD4qoQPC9KbMXLAG1B5 wMD8nJn3IAvZWMN4PosYGBSRMSqGizeOG2OCp9yqOGYaR+Bvp5XRXIh6JrrdiB4uxGs/ XWRXLQeYeNSs56cBDs00IkaDeZLbZPPlQ/jVSx/zY03SWXk389Gym98JIDyBIgEkbbdu CJ0twlGIObQXI7cNcOaF5bdsa5Ngl0trYTJV0pitVmvHT9m8M7xXKJFzBoUfFr0t7rgo 6GnAcaRQ57wEYwq08Os6GkESObr1iziQgHtg9fp1urUa35wXCLzJ+rEDeHnkDd2eoOv4 o2QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iVXZAHQG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si13537614edr.539.2021.05.31.09.54.23; Mon, 31 May 2021 09:54:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iVXZAHQG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234286AbhEaQyd (ORCPT + 99 others); Mon, 31 May 2021 12:54:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:51032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234372AbhEaO7V (ORCPT ); Mon, 31 May 2021 10:59:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DFC5F61CCA; Mon, 31 May 2021 14:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469668; bh=YN6Fa8RGRjU2S+rc9v9z1tqAVO9HBMiiCFEcAkIYEvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iVXZAHQGhFbb0Q8NYyJb4hwtb8VPyyYETfZIOcZxpyG9XPL6VPeQLyVA/e+RyB09R GlOUDm6eIjCIDf7jGjw8Kt2BvKHFvslQ6hJoFjetgCTjDRFBezwam/s5YOkhJxTu5B mwqcXf3aaq9dsryF/DCPtp0EtngEjMXPYJ+JtnLc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , Karsten Graul , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 250/296] net/smc: remove device from smcd_dev_list after failed device_add() Date: Mon, 31 May 2021 15:15:05 +0200 Message-Id: <20210531130712.173086965@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Julian Wiedmann [ Upstream commit 444d7be9532dcfda8e0385226c862fd7e986f607 ] If the device_add() for a smcd_dev fails, there's no cleanup step that rolls back the earlier list_add(). The device subsequently gets freed, and we end up with a corrupted list. Add some error handling that removes the device from the list. Fixes: c6ba7c9ba43d ("net/smc: add base infrastructure for SMC-D and ISM") Signed-off-by: Julian Wiedmann Signed-off-by: Karsten Graul Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/smc/smc_ism.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index 94b31f2551bc..967712ba52a0 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -429,6 +429,8 @@ EXPORT_SYMBOL_GPL(smcd_alloc_dev); int smcd_register_dev(struct smcd_dev *smcd) { + int rc; + mutex_lock(&smcd_dev_list.mutex); if (list_empty(&smcd_dev_list.list)) { u8 *system_eid = NULL; @@ -448,7 +450,14 @@ int smcd_register_dev(struct smcd_dev *smcd) dev_name(&smcd->dev), smcd->pnetid, smcd->pnetid_by_user ? " (user defined)" : ""); - return device_add(&smcd->dev); + rc = device_add(&smcd->dev); + if (rc) { + mutex_lock(&smcd_dev_list.mutex); + list_del(&smcd->list); + mutex_unlock(&smcd_dev_list.mutex); + } + + return rc; } EXPORT_SYMBOL_GPL(smcd_register_dev); -- 2.30.2