Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2300351iof; Wed, 8 Jun 2022 01:52:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+KR9MIczT522Zr5sW4OQSAfjJvzgXzyHBUhXw8C0NsT/y3mHHDflkkK/rMKPBvn4eGypJ X-Received: by 2002:a17:902:ef93:b0:163:de9e:edf8 with SMTP id iz19-20020a170902ef9300b00163de9eedf8mr33168839plb.151.1654678365365; Wed, 08 Jun 2022 01:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654678365; cv=none; d=google.com; s=arc-20160816; b=EXeSl9pw9s8GerxwVFPdJjFIazwuySlW1xkL6a4VB//AefiX4Mc1kcx0j+OQPlh+aS J5a7qzMALp4QnX27h1uK6/qD95RKE+GHS+6/4d/i5cP+iW6fA8GV7nD+Q7L3Yi8cKNTp Shn8e1T/wW8e/LAWDEzJRbp6tJkzm/Hje1rI2rH+Qlg6UOT+JY6A0OIQHNWt9sZQl4a0 jgqAOs92QdPF8NvPBEvu4JukBKHlbVGS0+Xgjd+Fk5YS1RywYQbkT8tpc0an5GU7RISp Q9FGQJSYcJ7fzlCRQRWLBV7rmZJQkaP9XWhRzMEcQLw1Z7mc9j5EaYdriv1JHQCC5ffs 5YUQ== 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=kSepvtfwokJPYay89aTgEujRKlSUQTDtw4sGwaLeh4c=; b=L9K6SvPKfff5IScf8Ohe/oapGIOlpGUhiDeH77iLiRsIWTv5QvkJAXGtIDthcjxsOG +2mUjP7O2PRkD/P5eVFffhoa/6bTd2Gj3hosyTYG4PErwHM+y79M19DpQaOSbwd3UueL Yx/cTdWu9SeXdyeiSVpnv0hxXFNVQqQjF1Om3OzbdRZ2UIhVKUiIhzeRAFZiLSf0K8kk Z43ipa6eEQc6G6Pwa+AB3HrMliQfzVB4vOsqbSi5kpIX3onoL3lRk58BbJd87p0m3/xt VnTV3P8e/8oEeafju6d9LbQRmaiUwOYk6mvU51zq/gwT8xRlwumToCM/XN5xqvD0EdIB jyQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="g9I4vEx/"; 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 x16-20020a17090a8a9000b001e3495408d6si27906833pjn.123.2022.06.08.01.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:52:45 -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="g9I4vEx/"; 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 52E5E2875B5; Wed, 8 Jun 2022 01:15:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349575AbiFGRvV (ORCPT + 99 others); Tue, 7 Jun 2022 13:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347056AbiFGReW (ORCPT ); Tue, 7 Jun 2022 13:34:22 -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 41F98109180; Tue, 7 Jun 2022 10:30:32 -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 DECA3614B5; Tue, 7 Jun 2022 17:30:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAE5DC34119; Tue, 7 Jun 2022 17:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623030; bh=tG1zL6GalKriyQc71pB4vzEjNZy47Fpf0YjX5DFgr5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9I4vEx/1JKOnMcAxv0TsE//wqU0o4BhxYkhYTeC3ts3x0+d4PHVnjfusEh//MpxC zYAWdxyWNV3tbd/T3NQV1B8UsfnBZAhBKeOsgSjVm+cyNdR2t0xb7KmWkmLEO4CiHi BfcLGDCHqGKge3ozOOrqe3r6R9mMcJF716OmvHPE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Prashant Malani , Tzung-Bi Shih , Sasha Levin Subject: [PATCH 5.10 270/452] platform/chrome: cros_ec: fix error handling in cros_ec_register() Date: Tue, 7 Jun 2022 19:02:07 +0200 Message-Id: <20220607164916.597407000@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: Tzung-Bi Shih [ Upstream commit 2cd01bd6b117df07b1bc2852f08694fdd29e40ed ] Fix cros_ec_register() to unregister platform devices if blocking_notifier_chain_register() fails. Also use the single exit path to handle the platform device unregistration. Fixes: 42cd0ab476e2 ("platform/chrome: cros_ec: Query EC protocol version if EC transitions between RO/RW") Reviewed-by: Prashant Malani Signed-off-by: Tzung-Bi Shih Signed-off-by: Sasha Levin --- drivers/platform/chrome/cros_ec.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c index 3104680b7485..979f92194e81 100644 --- a/drivers/platform/chrome/cros_ec.c +++ b/drivers/platform/chrome/cros_ec.c @@ -175,6 +175,8 @@ int cros_ec_register(struct cros_ec_device *ec_dev) ec_dev->max_request = sizeof(struct ec_params_hello); ec_dev->max_response = sizeof(struct ec_response_get_protocol_info); ec_dev->max_passthru = 0; + ec_dev->ec = NULL; + ec_dev->pd = NULL; ec_dev->din = devm_kzalloc(dev, ec_dev->din_size, GFP_KERNEL); if (!ec_dev->din) @@ -231,18 +233,16 @@ int cros_ec_register(struct cros_ec_device *ec_dev) if (IS_ERR(ec_dev->pd)) { dev_err(ec_dev->dev, "Failed to create CrOS PD platform device\n"); - platform_device_unregister(ec_dev->ec); - return PTR_ERR(ec_dev->pd); + err = PTR_ERR(ec_dev->pd); + goto exit; } } if (IS_ENABLED(CONFIG_OF) && dev->of_node) { err = devm_of_platform_populate(dev); if (err) { - platform_device_unregister(ec_dev->pd); - platform_device_unregister(ec_dev->ec); dev_err(dev, "Failed to register sub-devices\n"); - return err; + goto exit; } } @@ -264,12 +264,16 @@ int cros_ec_register(struct cros_ec_device *ec_dev) err = blocking_notifier_chain_register(&ec_dev->event_notifier, &ec_dev->notifier_ready); if (err) - return err; + goto exit; } dev_info(dev, "Chrome EC device registered\n"); return 0; +exit: + platform_device_unregister(ec_dev->ec); + platform_device_unregister(ec_dev->pd); + return err; } EXPORT_SYMBOL(cros_ec_register); -- 2.35.1