From patchwork Thu Jun 23 07:53:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9194653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D186D6075A for ; Thu, 23 Jun 2016 07:55:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C36292842E for ; Thu, 23 Jun 2016 07:55:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B79A72843B; Thu, 23 Jun 2016 07:55:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 572612842E for ; Thu, 23 Jun 2016 07:55:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFzSR-0001l7-1u; Thu, 23 Jun 2016 07:53:51 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bFzSN-0001Zq-GS for linux-arm-kernel@lists.infradead.org; Thu, 23 Jun 2016 07:53:48 +0000 Received: by mail-pa0-x230.google.com with SMTP id hl6so25077728pac.2 for ; Thu, 23 Jun 2016 00:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=/lt0AS2HPCYJTYz4dFd76NGa1j0dhTj2klQ5A66VK0E=; b=JWYWju0Z5qLYR8uWXuW8EolKoEqTVnYG4+Mb/CzS1QxT0q4f+ogJ4HW6FVZ4AEb7dl fG/IWomNxRo7xRXeltlk20DGC7iOe+Iz5NPGcQ9f0nS/HzKWDrJE7brEUyUhJZgOI8in hLoiocmC+WbJCuITVn3Xl/BbhfbJwhxIYbiRQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/lt0AS2HPCYJTYz4dFd76NGa1j0dhTj2klQ5A66VK0E=; b=Cqekp6WqFb6zmw6khKb4iU4ORfaFtT9/3LabwEe0kznXEmDxicPTpbBTMeSoLsMn0S hYgOslAr/HuYcjpInfucBddhoIEIg/TLgwwawiQrDi9HYtYpFOArV5un39puXGJKDnDH idc4LtjcFFanTjfG+Jd1oFIeqsYnTWg2GsyNOQicM49chYWLKu88a9DHcunatTmH94Jy aHFYUM/p0xwHtABNExvmGir7XOydTHeiWRk8qRoul+HjY1nyrlX9N4pfTOMiD+PdVHCJ ibCwddcdscIsF2DOM25Tn0/YxwVR36oTJQ0pHGQLIAUngLsxZ3D8HJhCuV22Y6jbYTW6 eRbA== X-Gm-Message-State: ALyK8tJ8Dz1CR6RcuZlM6I95EzBka5lSTUyfOltDQ+DI8NEHMeco4kB3NclNlnSf0ZiKyxTi X-Received: by 10.66.63.35 with SMTP id d3mr41015334pas.69.1466668406271; Thu, 23 Jun 2016 00:53:26 -0700 (PDT) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id d2sm4877999pfc.37.2016.06.23.00.53.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Jun 2016 00:53:25 -0700 (PDT) From: Stephen Boyd To: Chanwoo Choi Subject: [PATCH] extcon: Check for incorrect connection type in notifier register Date: Thu, 23 Jun 2016 00:53:24 -0700 Message-Id: <20160623075324.21935-1-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.9.0.rc2.8.ga28705d X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160623_005347_574735_BB9C1CCC X-CRM114-Status: GOOD ( 10.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If we call extcon_register_notifier() with the wrong cable type, it blows up with an oops instead of returning an error code. Let's be nice and fail gracefully given that the consumer might not know if the cable is supported by the extcon provider. Signed-off-by: Stephen Boyd --- drivers/extcon/extcon.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 21a123cadf78..161acb826334 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -586,6 +586,8 @@ int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, return -EINVAL; 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); @@ -611,6 +613,8 @@ int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, return -EINVAL; idx = find_cable_index_by_id(edev, id); + if (idx < 0) + return idx; spin_lock_irqsave(&edev->lock, flags); ret = raw_notifier_chain_unregister(&edev->nh[idx], nb);