From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932452AbcLSMOk (ORCPT ); Mon, 19 Dec 2016 07:14:40 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:35719 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932310AbcLSMOi (ORCPT ); Mon, 19 Dec 2016 07:14:38 -0500 X-AuditID: cbfee61b-f79d86d00000197e-3c-5857cf2cdf3d From: Chanwoo Choi To: linux-kernel@vger.kernel.org Cc: cw00.choi@samsung.com, chanwoo@kernel.org, myungjoo.ham@samsung.com Subject: [PATCH] extcon: Remove potential problem of extcon_register_notifier() when edev parameter is NULL Date: Mon, 19 Dec 2016 21:14:34 +0900 Message-id: <1482149674-19308-1-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFLMWRmVeSWpSXmKPExsVy+t9jQV2d8+ERBmuf8VtMvHGFxeL6l+es Fpd3zWGzuN24gs2BxWPTqk42j74tqxg9Pm+SC2COcrPJSE1MSS1SSM1Lzk/JzEu3VQoNcdO1 UFLIS8xNtVWK0PUNCVJSKEvMKQXyjAzQgINzgHuwkr5dglvG3fbfLAWz+CpuT97A3MB4lLuL kZNDQsBE4unXFkYIW0ziwr31bF2MXBxCArMYJQ69X8YK4fxglPhxZjUbSBWbgJbE/hc3wGwR AQWJzb3PWEFsZgF3iQ8/+pm7GDk4hAVyJTZPzwMxWQRUJRY1VYBU8Aq4Sqx+uJkZYpecxIc9 j9gnMHIvYGRYxSiRWpBcUJyUnmuUl1quV5yYW1yal66XnJ+7iREcbs+kdzAe3uV+iFGAg1GJ h/fA6fAIIdbEsuLK3EOMEhzMSiK890FCvCmJlVWpRfnxRaU5qcWHGE2B9k9klhJNzgfGQl5J vKGJuYm5sYGFuaWliZGSOG/j7GfhQgLpiSWp2ampBalFMH1MHJxSDYyuKy825D96zuJskT7r YkYG8/dKtyznRVkxZ12e34vY4COix7Gu5zr3p7Qfz/Qun9p52v9N/8XG3n95nfx8Ypam4gEq P64usxBy8JA6YDbL1vrVFs3lCgc2z53KuOi+lvhOEfsolYOykapby4vMO2MCfMPnJr0/2n3X b1FQnMBdmUat7UZfZymxFGckGmoxFxUnAgDf0zX6TQIAAA== X-MTR: 20000000000000000@CPGS Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch removes the potential problem of extcon_register_notifier() when edev parameter is NULL. When edev is NULL, this function returns the first extcon device which includes the sepecific external connector of second paramter. But, it don't guarantee the same operation in all cases. To remove this confusion and potential problem, this patch fixes it. Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 7c1e3a7b14e0..d0e367959c91 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -906,35 +906,16 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, unsigned long flags; int ret, idx = -EINVAL; - if (!nb) + if (!edev || !nb) return -EINVAL; - if (edev) { - idx = find_cable_index_by_id(edev, id); - if (idx < 0) - return idx; - - spin_lock_irqsave(&edev->lock, flags); - ret = raw_notifier_chain_register(&edev->nh[idx], nb); - spin_unlock_irqrestore(&edev->lock, flags); - } else { - struct extcon_dev *extd; - - mutex_lock(&extcon_dev_list_lock); - list_for_each_entry(extd, &extcon_dev_list, entry) { - idx = find_cable_index_by_id(extd, id); - if (idx >= 0) - break; - } - mutex_unlock(&extcon_dev_list_lock); + idx = find_cable_index_by_id(edev, id); + if (idx < 0) + return idx; - if (idx >= 0) { - edev = extd; - return extcon_register_notifier(extd, id, nb); - } else { - ret = -ENODEV; - } - } + spin_lock_irqsave(&edev->lock, flags); + ret = raw_notifier_chain_register(&edev->nh[idx], nb); + spin_unlock_irqrestore(&edev->lock, flags); return ret; } -- 1.9.1