From patchwork Thu Jul 5 13:36:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 10509233 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 0BDA2600F5 for ; Thu, 5 Jul 2018 13:37:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE633288FD for ; Thu, 5 Jul 2018 13:37:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2712289B9; Thu, 5 Jul 2018 13:37:04 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79BA4288FD for ; Thu, 5 Jul 2018 13:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932158AbeGENgv (ORCPT ); Thu, 5 Jul 2018 09:36:51 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:33166 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753935AbeGENgu (ORCPT ); Thu, 5 Jul 2018 09:36:50 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1fb4RD-0000in-I2; Thu, 05 Jul 2018 13:36:47 +0000 From: Colin King To: Heikki Krogerus , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][V2] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful Date: Thu, 5 Jul 2018 14:36:47 +0100 Message-Id: <20180705133647.13016-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King One of the error handling paths forgets to unlock dp->lock on the error exit path leading to a potential lock-up. Also the return path for a successful call to the function configuration_store can return an uninitialized error return code if dp->alt->active is false, so ensure ret is zeroed on the successful exit path to avoid garbage being returned. Detected by CoverityScan, CID#1471597 ("Unitialized scalar variable") Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode") Signed-off-by: Colin Ian King Acked-by: Heikki Krogerus --- V2: move the ret = 0 assignment to the declaration --- drivers/usb/typec/altmodes/displayport.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index ef12b15bd484..3f06e94771a7 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -333,7 +333,7 @@ configuration_store(struct device *dev, struct device_attribute *attr, u32 conf; u32 cap; int con; - int ret; + int ret = 0; con = sysfs_match_string(configurations, buf); if (con < 0) @@ -349,8 +349,10 @@ configuration_store(struct device *dev, struct device_attribute *attr, cap = DP_CAP_CAPABILITY(dp->alt->vdo); if ((con == DP_CONF_DFP_D && !(cap & DP_CAP_DFP_D)) || - (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D))) - return -EINVAL; + (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D))) { + ret = -EINVAL; + goto err_unlock; + } conf = dp->data.conf & ~DP_CONF_DUAL_D; conf |= con;