Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4208340ioa; Tue, 26 Apr 2022 20:54:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZIAJMpS+E9lbdEftK4wDWayE81k2WemUCPXkND4Py6IEbkew5PJ/d2h2HavyDZXzxBCAc X-Received: by 2002:a17:907:3da3:b0:6ef:f8e3:cf1a with SMTP id he35-20020a1709073da300b006eff8e3cf1amr24334697ejc.300.1651031667004; Tue, 26 Apr 2022 20:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651031666; cv=none; d=google.com; s=arc-20160816; b=LsqVjCNk+P2yRd4azoQ+ts/I3OIBNkD2p4OJIIu2YgdYBiN6rIox2ERAB3taUR6xtX Jp47fgXk55h8ZOwdb8IX8tBMn/a4LUCfSgl+tKQdDs91CVwSamK5tUNin/7DxJ3wNZJQ XpL5xoU4GqBtyPksj/S7PJIXaJGGV7Ln2iJ66FH0hJe5CwPMZSx0eIaaEUPczFICiX/j iBBQvGXiVuBJ9G9C+JFHhdm8FLrkYHL1qL8wCIzNFwdqbG+IHg6gE3JQuBCh7owSPaL4 tQp3+w5R3ExIVZDDytIM37hafQSLPdZo664+rO6gKRp9zBvvaSq7TeIiTu3k3m4HZBiC b2EA== 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-language :thread-index:content-transfer-encoding:mime-version:message-id:date :subject:in-reply-to:to:from:dkim-signature:dkim-filter; bh=0xKMt0dth//1sSAVFMOVRC/5a7GyV79msXh8HSh/flM=; b=yR7bTXntl2Af/9BeKZEEwyqixWesOsUt0APOAJHx1YhkAeCz1s8JeINi1oGBr1mqhx ux3OOJ9/NzqMpJhjJl9dnuO8WHco6+fREY2Va2kxu+PQejfHVcCkNWsp80Zpl04BE0E6 RnssaM8QfS6Iqhcw8/A+KJSlFpvYjjbBcuIqduqgne+sI/r2TCw6dmKhvpJjRQJu1OnW mJg6W8rjSjy2w4vUy7KxQiNqn/KJyBAF0/K4fAVbqfIpOzIgXtGdiHVh3uLS46TQU7/d In69Vg2vlLkHDPjA+Od4yF7Qkgo4K+95nMMJp5u5rMG9HEF4mHkPj4A2jTFBFPYztu6V kEog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=DFrY9A4G; 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=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020a17090657c400b006e888f4512esi125668ejr.982.2022.04.26.20.54.01; Tue, 26 Apr 2022 20:54:26 -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=@samsung.com header.s=mail20170921 header.b=DFrY9A4G; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357092AbiD0CPp (ORCPT + 99 others); Tue, 26 Apr 2022 22:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245545AbiD0CPk (ORCPT ); Tue, 26 Apr 2022 22:15:40 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E993D41F9F for ; Tue, 26 Apr 2022 19:12:29 -0700 (PDT) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220427021227epoutp015096fd23f3dc653ff2e87ab778052a60~pnvz3MaIb1461614616epoutp013 for ; Wed, 27 Apr 2022 02:12:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220427021227epoutp015096fd23f3dc653ff2e87ab778052a60~pnvz3MaIb1461614616epoutp013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651025547; bh=0xKMt0dth//1sSAVFMOVRC/5a7GyV79msXh8HSh/flM=; h=From:To:In-Reply-To:Subject:Date:References:From; b=DFrY9A4G0Ic8Nfv1lva5VD1OAWaJpq1iWAP9c/ptwvAx7rsx0OjfOUW3jeTHwx5eF IF4UGKlI/EGr/Cx11xyK8l92OYVo4aoKXJHLylZMM261NuoUgdeprpXu1F2cMNxdAL zY4sfCiRSpMjiCLzwQq6PYYbQzzuJXzaJfnsWECY= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20220427021227epcas1p49c14251aa06e5ae166d5f993223f13ab~pnvzm5I433178031780epcas1p4q; Wed, 27 Apr 2022 02:12:27 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.247]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4Kp2MG70lpz4x9QG; Wed, 27 Apr 2022 02:12:26 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id C3.F6.10063.A86A8626; Wed, 27 Apr 2022 11:12:26 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220427021226epcas1p2e1a991bf9f58298bb4476c87c9064bb0~pnvy37cRM1438414384epcas1p2B; Wed, 27 Apr 2022 02:12:26 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220427021226epsmtrp11b00d82476f9619d22c97932e22f2fa8~pnvy3Nt3G0104201042epsmtrp1W; Wed, 27 Apr 2022 02:12:26 +0000 (GMT) X-AuditID: b6c32a35-1dbff7000000274f-73-6268a68acd48 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 46.34.08924.A86A8626; Wed, 27 Apr 2022 11:12:26 +0900 (KST) Received: from bw365lee03 (unknown [10.88.97.170]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220427021226epsmtip16460a3afc85e50623a8a95382e4e7a65~pnvyqJeod2115021150epsmtip1Z; Wed, 27 Apr 2022 02:12:26 +0000 (GMT) From: =?UTF-8?B?7J2067KU7Jqw?= To: "'Chanwoo Choi'" , "'MyungJoo Ham'" , "'Chanwoo Choi'" , In-Reply-To: <6f07e65b-339a-1ff7-1959-9ea4758d5244@gmail.com> Subject: RE: [PATCH] extcon: modify extcon device to be created after driver data is set Date: Wed, 27 Apr 2022 11:12:26 +0900 Message-ID: <001e01d859dc$3d4d6870$b7e83950$@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQN4yMk10aQ8kdeD9OhaFXryx5/BvwITpb9EAcNqtAqpo24wsA== Content-Language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNKsWRmVeSWpSXmKPExsWy7bCmgW7XsowkgzsbLSyuf3nOavHsqLbF 5V1z2CxuN65gc2Dx2DnrLrtH35ZVjB6fN8kFMEdl22SkJqakFimk5iXnp2TmpdsqeQfHO8eb mhkY6hpaWpgrKeQl5qbaKrn4BOi6ZeYALVNSKEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2Cql FqTkFJgV6BUn5haX5qXr5aWWWBkaGBiZAhUmZGe8+qFXcNa04kj3GeYGxvsaXYycHBICJhIL vk1nB7GFBHYwSszeVwZhf2KUuL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ZSya0c1e8NK44saU A0wNjG3qXYycHBICJhJ7bi5n7mLk4hAS2MEo0XbsOAtEQlLi7PJH7F2MHEC2sMThw8UQNU8Z JTZtfMAIUsMmYCbR0biGBSQhIrCMUeL0gq1sIAkhgb2MEr8uhIDYnAK2EsuaDrOC2MICERL7 pzxjBrFZBFQlvu5rZgNZwCtgKXGoTQQkzCsgKHFy5hOwG5gFtCV6H7YywtjLFr5mhrhNQeLn 02VgI0UEnCQuXN3OBFEjIjG7s415AqPQLCSjZiEZNQvJqFlIWhYwsqxilEwtKM5Nzy02LDDK Sy3XK07MLS7NS9dLzs/dxAiOAC2tHYx7Vn3QO8TIxMF4iFGCg1lJhPeeYkaSEG9KYmVValF+ fFFpTmrxIUZpDhYlcd4LXSfjhQTSE0tSs1NTC1KLYLJMHJxSDUwhSo7Wu/bmbZ838X1CZn6q slvn05ANSnaz/nxlV78msuyln/LHS7NXnbfV/uX6YbNi+Vbnie5bMqaeV/hSyf3is2rIxoaE vuwEpfR0poStfW9m26yUPZUk85hX5HfhIzZhvmP9YuVaCS+E1pw6uuLXxeO7w8+4by+c/1Jn XmXbNc3/UUJbk67snb4gLXxjv7rRuUhdiTvmcse2xwcWKv/bXSidNWttrHxuxi6u2f8ePvFL Km/e+FvxxtLYhftfm1w7oHLI8/H/9HX6LRY+LVvWT9v9cOGTvMlyd1KtGCT8QlxahY1OtMlU /SqdU2/WVvKdNa56j33FCQHD/VoTzv6ZVv9qXlZw2E/R3Zbr599UYinOSDTUYi4qTgQAFvJj 5e8CAAA= X-CMS-MailID: 20220427021226epcas1p2e1a991bf9f58298bb4476c87c9064bb0 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: 20220331030336epcas1p3b8bf7b1841d4b246030b57b668312169 References: <20220331030324.42621-1-bw365.lee@samsung.com> <6f07e65b-339a-1ff7-1959-9ea4758d5244@gmail.com> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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 Hi chanwoo. Thank you for your review. Actually, I thought the same thing as you first. However, it was a problem because dev->devres_lock was not initialized and = devm_kcalloc was used, and this patch was created instead of using kcalloc = instead of devm_kcalloc. In your opinion, if I use kcalloc instead of devm_kcalloc, there will be no= problem. But, I think the code of the following part should be supplemented. 1. alloc edev->nh when edev->max_supported is none zero. =40=40 -1224,19 +1224,14 =40=40 int extcon_dev_register(struct extcon_dev *= edev) + if (edev->max_supported) =7B + edev->nh =3D kcalloc(edev->max_supported, sizeof(*edev->nh)= , + GFP_KERNEL); + if (=21edev->nh) =7B + ret =3D -ENOMEM; + goto err_alloc_nh; + =7D =7D 2. free evdev->nh when device unregister. =40=40 -1314,6 +1318,7 =40=40 void extcon_dev_unregister(struct extcon_dev = *edev) if (edev->max_supported) =7B kfree(edev->extcon_dev_type.groups); kfree(edev->cables); + kfree(edev->nh); =7D I will re-raise commit after testing. Please let me know if you have additional concern. Best Regards, Bumwoo Lee. -----Original Message----- From: Chanwoo Choi =20 Sent: Wednesday, April 27, 2022 2:09 AM To: bumwoo lee ; MyungJoo Ham ; Chanwoo Choi ; linux-kernel=40vger.kerne= l.org Subject: Re: =5BPATCH=5D extcon: modify extcon device to be created after d= river data is set Hi Bumwoo, Firstly, I'm sorry for late replay. On 22. 3. 31. 12:03, bumwoo lee wrote: > Currently, someone can invoke the sysfs such as state_show()=20 > intermittently before 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. >=20 > - Oops's backtrace. >=20 > Backtrace: > =5B=5D (state_show) from =5B=5D (dev_attr_show)=20 > =5B=5D (dev_attr_show) from =5B=5D (sysfs_kf_seq_show= )=20 > =5B=5D (sysfs_kf_seq_show) from =5B=5D (kernfs_seq_sh= ow)=20 > =5B=5D (kernfs_seq_show) from =5B=5D (seq_read)=20 > =5B=5D (seq_read) from =5B=5D (kernfs_fop_read)=20 > =5B=5D (kernfs_fop_read) from =5B=5D (__vfs_read)=20 > =5B=5D (__vfs_read) from =5B=5D (vfs_read) =5B=5D=20 > (vfs_read) from =5B=5D (ksys_read) =5B=5D (ksys_read)= from=20 > =5B=5D (sys_read) =5B=5D (sys_read) from =5B=5D=20 > (__sys_trace_return) >=20 > Signed-off-by: bumwoo lee > --- > drivers/extcon/extcon.c =7C 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index=20 > d27cd9f88f86..74fee04bd764 100644 > --- a/drivers/extcon/extcon.c > +++ b/drivers/extcon/extcon.c > =40=40 -1224,18 +1224,13 =40=40 int extcon_dev_register(struct extcon_dev= *edev) > edev->dev.type =3D &edev->extcon_dev_type; > =7D > =20 > - ret =3D device_register(&edev->dev); > - if (ret) =7B > - put_device(&edev->dev); > - goto err_dev; > - =7D > + device_initialize(&edev->dev); > =20 > spin_lock_init(&edev->lock); > edev->nh =3D devm_kcalloc(&edev->dev, edev->max_supported, > sizeof(*edev->nh), GFP_KERNEL); Actually, I'm not sure that it is proper to use 'edev->dev' by devm_kcalloc before device_add. When error happen between device_initial= ize and device_add, I think that it is not properly handled such as free th= e allocated memory automatically. > if (=21edev->nh) =7B > ret =3D -ENOMEM; > - device_unregister(&edev->dev); > goto err_dev; > =7D > =20 > =40=40 -1251,9 +1246,14 =40=40 int extcon_dev_register(struct extcon_dev = *edev) > list_add(&edev->entry, &extcon_dev_list); > mutex_unlock(&extcon_dev_list_lock); > =20 > + ret =3D device_add(&edev->dev); > + if (ret) > + goto err_dev; On this case, need to delete entry from extcon_dev_list by using list_del. > + > return 0; > =20 > err_dev: > + put_device(&edev->dev); > if (edev->max_supported) > kfree(edev->extcon_dev_type.groups); > err_alloc_groups: I recommend that move device_register() position after dev_set_drvdata. And then use kcalloc instead of devm_kcalloc as following: diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index d27cd9= f88f86..80e5bfec1131 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c =40=40 -1224,19 +1224,11 =40=40 int extcon_dev_register(struct extcon_dev *= edev) edev->dev.type =3D &edev->extcon_dev_type; =7D - ret =3D device_register(&edev->dev); - if (ret) =7B - put_device(&edev->dev); - goto err_dev; - =7D - spin_lock_init(&edev->lock); - edev->nh =3D devm_kcalloc(&edev->dev, edev->max_supported, - sizeof(*edev->nh), GFP_KERNEL); + edev->nh =3D kcalloc(edev->max_supported, sizeof(*edev->nh), GFP_KERNEL); if (=21edev->nh) =7B ret =3D -ENOMEM; - device_unregister(&edev->dev); - goto err_dev; + goto err_alloc_nh; =7D for (index =3D 0; index < edev->max_supported; index++) =40=40 -12= 47,6 +1239,12 =40=40 int extcon_dev_register(struct extcon_dev *edev) dev_set_drvdata(&edev->dev, edev); edev->state =3D 0; + ret =3D device_register(&edev->dev); + if (ret) =7B + put_device(&edev->dev); + goto err_dev; + =7D + mutex_lock(&extcon_dev_list_lock); list_add(&edev->entry, &extcon_dev_list); mutex_unlock(&extcon_dev_list_lock); =40=40 -1254,6 +1252,9 =40=40 int extcon_dev_register(struct extcon_dev *ed= ev) 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: =40=40 -1314,6 +1315,7 =40=40 void extcon_dev_unregister(struct extcon_dev = *edev) if (edev->max_supported) =7B kfree(edev->extcon_dev_type.groups); kfree(edev->cables); + kfree(edev->nh); =7D put_device(&edev->dev); -- Best Regards, Samsung Electronics Chanwoo Choi