Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp438649iog; Mon, 13 Jun 2022 06:02:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2WHtYBW/gKAoJ/Bb6oNECeWMMFlF5rTeSqEs/AcLalfMQoA+93WjB8Om/Rkf71bi3sRS4 X-Received: by 2002:a17:907:97d4:b0:711:cf0c:c220 with SMTP id js20-20020a17090797d400b00711cf0cc220mr35889280ejc.269.1655125372043; Mon, 13 Jun 2022 06:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125372; cv=none; d=google.com; s=arc-20160816; b=OF9e+B6pF44AUYCwOPy9T8T+rDJ//9P5AwaWj+cNe181NzxnkQfq+1uCrVgpSzGeaI xJ2cssHpaFCsaKQpzVeRhZM62xnk3iDkj8HMKp6QB6+X7WWw6KvU2oiI19DTHIHucxzR qaI2g2mWqdiUPTwUe99eBWd+jOwDGce1WS5VuSTZ0/MJTlY5MQGZIa73vzv/BNdZQSn5 a8OiJt5ZmpqkXU+hbEYz/yRJOIyhrWlX0YdUtZNpPJ3HjJBaTR+McimpvBJwrR5/ZRos K4NyQd5H/ECqMvW8Sw5EmDgzSBa8QGOTFuNCI6YB2uhzCFFMGP3itAJJr3t2vM8yz4z5 xbkQ== 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=l6GSUDTviUBlbFgGvNCQ9LpFS/xHcNN1gD0TKwV7aTA=; b=mupkwaVSoRO4XyqfGl8Od/6uzwy6hVA7vEEm8+g9iru+pLLZ+9T6P888VxshtbdNMr wNngerucPU6o+cqWgLYR8nhJdpGj544PiDHOvm7b3aBtiiJ5MY9W5A6L7WXCLunTgl2E 3rONPoaYvpBlaOgEs+hs1uMMFPADZ9cL5Wo0lkqc6czet8kcXyXO+2RWU910z8toBE5Y mriYv0YdHgQkK3bSUKo73MGp3nIWPRIhPkMqDBS5nmhQpcZjPxTqpyhWDsk7jVMgXSxF QwtwZW8v29lOO+MKOfslmPs1nU0AZnCF4oUN/7PNihc9zgVZvoUPy6yLHt04qlBFdzTi rpKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="q58wUsw/"; 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 h16-20020a05640250d000b0042df1a18128si8300385edb.620.2022.06.13.06.02.25; Mon, 13 Jun 2022 06:02:52 -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="q58wUsw/"; 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 S1356761AbiFMLvI (ORCPT + 99 others); Mon, 13 Jun 2022 07:51:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357065AbiFMLp3 (ORCPT ); Mon, 13 Jun 2022 07:45:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91F39B63; Mon, 13 Jun 2022 03:51:39 -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 059A7B80E07; Mon, 13 Jun 2022 10:51:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63B48C34114; Mon, 13 Jun 2022 10:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117496; bh=jMZXmEP/+RK0uQl0NLibbp+SHDtq/RGALhCcm54ehP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q58wUsw/QOIDN3URvAwdPhSa/1MJRXy4fETA5uyh8K5IOsjdcSA1AQUCBROtvbEgK lSDjhrDSfpfl4dCCuo4qrKsqiAaZe4mySAQ5yA8loAKcvxJ+bqgndvdsR2EegV79Rt ypjDJsNCqPfTrQSLnBmxyrf9jB4foJzEi1wMybuo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, bumwoo lee , Chanwoo Choi , Sasha Levin Subject: [PATCH 5.4 378/411] extcon: Modify extcon device to be created after driver data is set Date: Mon, 13 Jun 2022 12:10:51 +0200 Message-Id: <20220613094940.006563268@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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=-8.3 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 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: bumwoo lee [ Upstream commit 5dcc2afe716d69f5112ce035cb14f007461ff189 ] Currently, someone can invoke the sysfs such as state_show() intermittently before dev_set_drvdata() is done. And it can be a cause of kernel Oops because of edev is Null at that time. So modified the driver registration to after setting drviver data. - Oops's backtrace. Backtrace: [] (state_show) from [] (dev_attr_show) [] (dev_attr_show) from [] (sysfs_kf_seq_show) [] (sysfs_kf_seq_show) from [] (kernfs_seq_show) [] (kernfs_seq_show) from [] (seq_read) [] (seq_read) from [] (kernfs_fop_read) [] (kernfs_fop_read) from [] (__vfs_read) [] (__vfs_read) from [] (vfs_read) [] (vfs_read) from [] (ksys_read) [] (ksys_read) from [] (sys_read) [] (sys_read) from [] (__sys_trace_return) Signed-off-by: bumwoo lee Signed-off-by: Chanwoo Choi Signed-off-by: Sasha Levin --- drivers/extcon/extcon.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 5c9e156cd086..6b905c3d30f4 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1230,19 +1230,14 @@ int extcon_dev_register(struct extcon_dev *edev) edev->dev.type = &edev->extcon_dev_type; } - ret = device_register(&edev->dev); - if (ret) { - put_device(&edev->dev); - goto err_dev; - } - spin_lock_init(&edev->lock); - edev->nh = devm_kcalloc(&edev->dev, edev->max_supported, - sizeof(*edev->nh), GFP_KERNEL); - if (!edev->nh) { - ret = -ENOMEM; - device_unregister(&edev->dev); - goto err_dev; + if (edev->max_supported) { + edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), + GFP_KERNEL); + if (!edev->nh) { + ret = -ENOMEM; + goto err_alloc_nh; + } } for (index = 0; index < edev->max_supported; index++) @@ -1253,6 +1248,12 @@ int extcon_dev_register(struct extcon_dev *edev) dev_set_drvdata(&edev->dev, edev); edev->state = 0; + ret = device_register(&edev->dev); + if (ret) { + put_device(&edev->dev); + goto err_dev; + } + mutex_lock(&extcon_dev_list_lock); list_add(&edev->entry, &extcon_dev_list); mutex_unlock(&extcon_dev_list_lock); @@ -1260,6 +1261,9 @@ int extcon_dev_register(struct extcon_dev *edev) return 0; err_dev: + if (edev->max_supported) + kfree(edev->nh); +err_alloc_nh: if (edev->max_supported) kfree(edev->extcon_dev_type.groups); err_alloc_groups: @@ -1320,6 +1324,7 @@ void extcon_dev_unregister(struct extcon_dev *edev) if (edev->max_supported) { kfree(edev->extcon_dev_type.groups); kfree(edev->cables); + kfree(edev->nh); } put_device(&edev->dev); -- 2.35.1