Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4370611ioa; Wed, 27 Apr 2022 02:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQ+La1fYf7zi9E4N5n64+q5vBht2hj+wJyGlJaHbYEbgi8OKrNMi8i4WP8QC+YkO5O2Cse X-Received: by 2002:a17:902:b107:b0:15d:391c:5a72 with SMTP id q7-20020a170902b10700b0015d391c5a72mr7024515plr.46.1651050731904; Wed, 27 Apr 2022 02:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651050731; cv=none; d=google.com; s=arc-20160816; b=oMXjnZ+E103xBjAy3SWI/Ihh5ZwWIxuW3YzXoN+x97lD38ga7uaEVZpELZUlhKmgGI xw8p86WVWtoMpWGj/bC0fDuq1pO+nqTyPPjITCwCx2OmaXVGHMtAJBgpy31KscqZi/TC CpfrlVbdPG96RWsqTrADARzilQwLz2B+9QFYRPQkRU3qFpLJdq7X/Lk/6FgdyUuWjojP o0nKvIj5gijhPtct48+HqHgVuD5nBI08qOjypJ89vlZ4qEEBSbdXkfarkp8UGRZSCEzY CXI5g926hIzeKWBx81KQHXNfwwv2a6TXQC9TgZZU2lEenSVM6CKw7iIC9ux/kl7+KUu7 hWDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=M+qF4DXxSPrRE9hFKeagdW70MBluH+VPhyv/ruHbtFk=; b=nItKk6oto/AJVP6z0nsHvGZtA0rGo2vkPFunXSA/B29dGZiti3mw3uPb57bV7A+rZK ObtB90G91CIH8yy1YdhSnxUwX9pf/UmPaiOXZtTq50aoZDr0DRL72LQW2vvFbm9QF+Ue sKhJsNJxINLDlpA+8bYADeeWepF3sR/wgsNDhlV42HGMdN0vJjGvbJ+lEBC7DqinP/DJ Dr22ei1yOeTb7fLLiVWq2bC1Kltvf8w9WeNB7xBl3urhzGRow7p9BLFWNRj77pl6Wh/k x/3Rkw0LTF5quyO0cxgjd9agiRTYXlvZEqAt8EDpyyefUClhGRzeEmPNpplhfSn9zIaa NZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=ZPSNEyzG; 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=samsung.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j9-20020a056a00234900b00509fc34d6c4si956186pfj.173.2022.04.27.02.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 02:12:11 -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=@samsung.com header.s=mail20170921 header.b=ZPSNEyzG; 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=samsung.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 71BA22060D8; Wed, 27 Apr 2022 02:03:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356519AbiD0DET (ORCPT + 99 others); Tue, 26 Apr 2022 23:04:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239060AbiD0DEO (ORCPT ); Tue, 26 Apr 2022 23:04:14 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AD8633E2E for ; Tue, 26 Apr 2022 20:00:57 -0700 (PDT) Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220427030051epoutp047026342dc143f85ede405c592edf9304~poaENdlWz2909329093epoutp046 for ; Wed, 27 Apr 2022 03:00:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220427030051epoutp047026342dc143f85ede405c592edf9304~poaENdlWz2909329093epoutp046 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651028451; bh=M+qF4DXxSPrRE9hFKeagdW70MBluH+VPhyv/ruHbtFk=; h=From:To:Cc:Subject:Date:References:From; b=ZPSNEyzGhFo2+BL72wZ0TVcQnl5kcrX/8UGGkwnccnFjxN2ytDl/57vkDHUzvzHBL 338C36tSBEC6CxJOx72CE/PxQWtve6fYAKwt2ngg2MrgCafxhobsiwgsvwLmONd/r3 hEwWaQYf5LFrrIWhP4QPt9h24fMrdKYaRVyMbTPg= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20220427030051epcas1p29f7ba0710c568a6890428aaaede4cea0~poaD1ZqqB1652716527epcas1p2S; Wed, 27 Apr 2022 03:00:51 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.36.226]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4Kp3R65LLZz4x9Q9; Wed, 27 Apr 2022 03:00:50 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 20.0F.10038.2E1B8626; Wed, 27 Apr 2022 12:00:50 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20220427030050epcas1p377eb744ed82b0e4a80747da6229fedca~poaDPkY5P1145211452epcas1p3E; Wed, 27 Apr 2022 03:00:50 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220427030050epsmtrp2f0e0c68b59840001182e56cc8997775e~poaDOqag-2127921279epsmtrp2S; Wed, 27 Apr 2022 03:00:50 +0000 (GMT) X-AuditID: b6c32a37-111ff70000002736-c3-6268b1e2e061 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id EE.79.08924.2E1B8626; Wed, 27 Apr 2022 12:00:50 +0900 (KST) Received: from VDBS1418.vd.sec.samsung.net (unknown [168.219.244.30]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220427030050epsmtip115f5c27c8549c2acc80d468540c5f98e~poaC-4Jr42314923149epsmtip1j; Wed, 27 Apr 2022 03:00:50 +0000 (GMT) From: bumwoo lee To: MyungJoo Ham , Chanwoo Choi , linux-kernel@vger.kernel.org Cc: bumwoo lee Subject: [PATCH V1] extcon: modify extcon device to be created after driver data is set Date: Wed, 27 Apr 2022 12:00:05 +0900 Message-Id: <20220427030005.706-1-bw365.lee@samsung.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHKsWRmVeSWpSXmKPExsWy7bCmru6jjRlJBke3a1ucWLOIyeL6l+es Fpd3zWGzuN24gs2BxaNvyypGj8+b5AKYorJtMlITU1KLFFLzkvNTMvPSbZW8g+Od403NDAx1 DS0tzJUU8hJzU22VXHwCdN0yc4AWKSmUJeaUAoUCEouLlfTtbIryS0tSFTLyi0tslVILUnIK zAr0ihNzi0vz0vXyUkusDA0MjEyBChOyMz40TmEr+CFa8e3PKpYGxu1CXYwcHBICJhI7+3y7 GDk5hAR2MEqcO2XYxcgFZH9ilHg+6ycLhPOZUa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pGQlDi7/BGQzQFkC0scPlwMUfODUeLe4c3M IDVsAhoSFy9eB7NFBIolLhxYzAJiMwuoSfw508ME0issEC5xbncESJhFQFVi9e45YON5BSwk lpw9xgyxSl6i+98fFoi4oMTJmU+gxshLNG+dzTyBkW8WktQsJKkFjEyrGCVTC4pz03OLDQuM 8lLL9YoTc4tL89L1kvNzNzGCw0xLawfjnlUf9A4xMnEwHmKU4GBWEuG9p5iRJMSbklhZlVqU H19UmpNafIhRmoNFSZz3QtfJeCGB9MSS1OzU1ILUIpgsEwenVAPT5BsP+HbxbLY6lb1tXV3D m4gdU1m4p71Vkrj3/0jB681POzQ+3d3Htb+s7umJ5tmnnxYKyl/Q+n+CY8Hc/Puab0s3zf99 Z/GvH1d8PnW7bfZxUlSzurkt8tfnNw8KzVsVoqaGcMXfXW6S/23/NHstxajvHvLLdldo//6w Lv35I/UJngo3BGMzeVN2f6jx/X952j6TSeE3tuZ/jdc96P5D+HPyhM8CAQfcXLvMPSZ42l94 PWHOIdusaaHlR7ZMXnEl5Xj4oXtzZd/H/+Wdc4hxXpxE7xTZxN+6q7RdXy4qj6oo+v6UbWbw 7LD9M/X2Bq1Jt7xY1zerXDF2QXSwhLz/wvn60tqmRjv+3+X47BB36JQSS3FGoqEWc1FxIgB2 y7A1ogIAAA== X-CMS-MailID: 20220427030050epcas1p377eb744ed82b0e4a80747da6229fedca X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220427030050epcas1p377eb744ed82b0e4a80747da6229fedca References: X-Spam-Status: No, score=-2.5 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 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 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 --- 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 d27cd9f88f86..d3a32b806499 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1224,19 +1224,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++) @@ -1247,6 +1242,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); @@ -1254,6 +1255,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: @@ -1314,6 +1318,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