From patchwork Wed Jul 4 12:46:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 10506809 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 CA7EB60325 for ; Wed, 4 Jul 2018 12:46:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC7A528DDD for ; Wed, 4 Jul 2018 12:46:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B002E28DE3; Wed, 4 Jul 2018 12:46:16 +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 3C96428DDD for ; Wed, 4 Jul 2018 12:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753294AbeGDMqO (ORCPT ); Wed, 4 Jul 2018 08:46:14 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:43201 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753231AbeGDMqN (ORCPT ); Wed, 4 Jul 2018 08:46:13 -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 1fahAh-0001Hu-Fp; Wed, 04 Jul 2018 12:46:11 +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][next] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful Date: Wed, 4 Jul 2018 13:46:11 +0100 Message-Id: <20180704124611.9852-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 --- drivers/usb/typec/altmodes/displayport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index ef12b15bd484..9a637c2b4460 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -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; @@ -362,6 +364,7 @@ configuration_store(struct device *dev, struct device_attribute *attr, } dp->data.conf = conf; + ret = 0; err_unlock: mutex_unlock(&dp->lock);