Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp59562pja; Fri, 22 Nov 2019 03:26:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzzATazu5bYILtHtCBjBEwp83HQrQMDYnoIyqHkem2FMt9QM25AfuoPyfe1fl/lOcMb29SQ X-Received: by 2002:aa7:c453:: with SMTP id n19mr440745edr.103.1574421993863; Fri, 22 Nov 2019 03:26:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421993; cv=none; d=google.com; s=arc-20160816; b=HbENe7T/bweNUlzHcACat4ZB9YRrJk9w4DMo7LZsretC4nhJGv2I6XkMK8VaGZ03WZ HpOJEDRl++VBU7xHCGjYv3s+B+FDp/KfuQYRiW7ihaAkdws67R/mK2VMpxEJWusexQ/4 m2K9Xb7wg+gQx/gM5RZ7eoaPDqMmQgknUHMVyWFSAqVIKMOQB8WvZiD7f+s70C06v0i/ g+A5drWyiQLN8uD5TNt0mimz4n6k+pW9FSXimoErz2lSXxfJYEZVrSPIakR0B0bBPkgx +2Z06/kzGAmjGktQHUNYBgQzLy0fCuqJuukWkWa3MHR8G+lgeeYyJGAJyP3U1IXw8gd4 9JwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WKjRo4iw0Iasbv/my6ReWoyTcOSFV8AcfRZy8StS26c=; b=a+ahMwMFwEkkwFyUyH1wA6OQga+v1TWPIdzjiFN83kpBQdEe/CvIB0pnEuIYuXKKBi bJQ0Uqjwi29aSJ2+4kcSDmO9lbg+UkqzFEyHum0IgzIKsXAQ8Ga38pg5Z8L1mQKzID1/ ULgGYBfRONAYXuVWaPr/gRhe1kcpg2PZkTu8FpahZi9JYpAMj5Y/f0wqQjvTDUG/qScI hYPw101su58p+Mz0lEELJvZpRRthbCgLunjEdS2GR8OCggV9VagSj8sdmNvFsYXh7Rwd /nXI6jSv1tkO93OPdTO3IkPbeKJR6cvILE+ZRa/Nd4FcxH2pscOWzq9m5hyaaimpdPkz ZVQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RvzWVjvK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si3947166eje.253.2019.11.22.03.26.10; Fri, 22 Nov 2019 03:26:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RvzWVjvK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727912AbfKVKoZ (ORCPT + 99 others); Fri, 22 Nov 2019 05:44:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:50192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727551AbfKVKoU (ORCPT ); Fri, 22 Nov 2019 05:44:20 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 429EF20656; Fri, 22 Nov 2019 10:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574419459; bh=yghk864Qu3p4uLxrXvRwD8kPFl/idh9sgYH6Bz1/LXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RvzWVjvKO0ZYveBauCLDNuPGu/MrFGhFRl1lcAke1bzfp5K3MPNdCpEf1igWnHpb4 Q0ZGsd6FwJFshirtF59eegtwNCpNDqq/a6xrOo5XJfXxoFaml+JJrNdSn4n2mXIeRS edGctmSo7OpfZtcSYWSPmWWDPapxqEvldrMissRM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Banajit Goswami , Sasha Levin Subject: [PATCH 4.9 075/222] component: fix loop condition to call unbind() if bind() fails Date: Fri, 22 Nov 2019 11:26:55 +0100 Message-Id: <20191122100908.296435014@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100830.874290814@linuxfoundation.org> References: <20191122100830.874290814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Banajit Goswami [ Upstream commit bdae566d5d9733b6e32b378668b84eadf28a94d4 ] During component_bind_all(), if bind() fails for any particular component associated with a master, unbind() should be called for all previous components in that master's match array, whose bind() might have completed successfully. As per the current logic, if bind() fails for the component at position 'n' in the master's match array, it would start calling unbind() from component in 'n'th position itself and work backwards, and will always skip calling unbind() for component in 0th position in the master's match array. Fix this by updating the loop condition, and the logic to refer to the components in master's match array, so that unbind() is called for all components starting from 'n-1'st position in the array, until (and including) component in 0th position. Signed-off-by: Banajit Goswami Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/base/component.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f2ffd22..08da6160e94dd 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -461,9 +461,9 @@ int component_bind_all(struct device *master_dev, void *data) } if (ret != 0) { - for (; i--; ) - if (!master->match->compare[i].duplicate) { - c = master->match->compare[i].component; + for (; i > 0; i--) + if (!master->match->compare[i - 1].duplicate) { + c = master->match->compare[i - 1].component; component_unbind(c, master, data); } } -- 2.20.1