Message ID | 20221216162126.207863-3-helgaas@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1061981wrn; Fri, 16 Dec 2022 08:22:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7cuJoWnWqFSlER+6CVLYsy9ykR7sjlAV91iRjykchB05P6GnsVqPdLxg3yMsVZFA2sGVlh X-Received: by 2002:a17:906:4c4b:b0:7c1:1ada:5e1e with SMTP id d11-20020a1709064c4b00b007c11ada5e1emr27376565ejw.26.1671207770498; Fri, 16 Dec 2022 08:22:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671207770; cv=none; d=google.com; s=arc-20160816; b=f8QEyOOKIndtSLz9jFLJFwCDpmGi5Rbij3VYhyr0SpR7RDHFjj6feDQ9EHg8Y+p5tA UELHA+G96cHwKsbEEPT+JDiCzc9wGOryO+gtk22GhK9DP15l+q3dQtl9+lY3G2ujjTzA Iq7uOkGhNrcYk8w/iM98tHxrB+t16A8nM3vPw41ShUulr4d97LTd7AlynvO57sgHtaY5 st5WPCHr6NDcMTeMOJJVOWRKcyv+l1p2wIEKYqozs1GGyWANVw7ZdeKlXRlwR5WTAZzr SjusDJhplHaGp4VPNq2hP+EKVeKZTw8vemTPv7IwkeCNbHG7+76F4KHK5HPOeW0aYS1f WjiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4osyqz6wQplMW//vqUobJtB+lB8hcu5CaPkMps5JI1E=; b=zakhYRNlcw4M1CpUngUyyuIUFz+NNu2r7ojNueHoAFp5qAyIDN9RYhKKiv2DXgpKqR Eikj0VZbC+i4A3UB3/enDLru/HuJYkXvCWWtbVr5EZqcSu0vfFKbk7fOysUSO4s26aWv u/pKCLHyX14r3fZ9GXlk5FGsl4SMtbfn1QGdRPEhxJGu0GseGo665vl79a0XOP+sJXeF 9W4WgyFKf8NlrAEpIXf6RLamDFVFaYLQzDiy8uXvwUpBsaXAr0I/VRlPZMnDAahiD2qO 7+dmH05Mxq9puDONLzikKBrFQW7VHLo2o2J9cbxsS3kmsK0cGfrqBUQcpueZvZ12T6gX 91Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oi2Et4Gf; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lv26-20020a170906bc9a00b007d6648874adsi2204450ejb.751.2022.12.16.08.22.26; Fri, 16 Dec 2022 08:22:50 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=oi2Et4Gf; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231702AbiLPQWM (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Fri, 16 Dec 2022 11:22:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231687AbiLPQVh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 16 Dec 2022 11:21:37 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B95752A271; Fri, 16 Dec 2022 08:21:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 53E1C61FDD; Fri, 16 Dec 2022 16:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 849D6C433EF; Fri, 16 Dec 2022 16:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671207695; bh=rf/kiQvV904IrlTYmlNmOzv2wh9Ar7q41y6LIAE+Or8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oi2Et4GfdoQdyzLPIZ1SbYq8/8VIHiwgSJ8mxaRLr6tXw93y0Orz1U8kNwvkiyzax jOAwBgAmT3ETkYxFYShh4bNuy1iTF2w4DVjtgOApePWMIPNtXM9RKIJ3VkufRsQDbu QjtjhaheDWP8YcIQsOriWOXmytdi5oXNWuV+cHv3aMGGx6YC2yNE1qcjixaTYc5DEI ih/tZ0yRxyNr7RfPiO7+kT0vnOgb/UQw0VzCC+RVB4q6P2V+M6ROgnLqwfqaMIAaNY zMFEBXK8UOKZZGsmOHfZRASO4yNwtWFJzoRN2Bxh0Jo7k0POhT6WtiPYFMZWCYXVhm ah3wEyI9OZmYQ== From: Bjorn Helgaas <helgaas@kernel.org> To: Kurt Schwemmer <kurt.schwemmer@microsemi.com>, Logan Gunthorpe <logang@deltatee.com> Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com> Subject: [PATCH v2 2/2] PCI: switchtec: Return -EFAULT for copy_to_user() errors Date: Fri, 16 Dec 2022 10:21:26 -0600 Message-Id: <20221216162126.207863-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221216162126.207863-1-helgaas@kernel.org> References: <20221216162126.207863-1-helgaas@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752388359162082140?= X-GMAIL-MSGID: =?utf-8?q?1752388359162082140?= |
Series |
PCI: switchtec: Trivial cleanups
|
|
Commit Message
Bjorn Helgaas
Dec. 16, 2022, 4:21 p.m. UTC
From: Bjorn Helgaas <bhelgaas@google.com> switchtec_dev_read() didn't handle copy_to_user() errors correctly: it assigned "rc = -EFAULT", but actually returned either "size", -ENXIO, or -EBADMSG instead. Update the failure cases to unlock mrpc_mutex and return -EFAULT directly. Fixes: 080b47def5e5 ("MicroSemi Switchtec management interface driver") Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> --- drivers/pci/switch/switchtec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On 2022-12-16 09:21, Bjorn Helgaas wrote: > From: Bjorn Helgaas <bhelgaas@google.com> > > switchtec_dev_read() didn't handle copy_to_user() errors correctly: it > assigned "rc = -EFAULT", but actually returned either "size", -ENXIO, or > -EBADMSG instead. > > Update the failure cases to unlock mrpc_mutex and return -EFAULT directly. > > Fixes: 080b47def5e5 ("MicroSemi Switchtec management interface driver") > Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Looks good to me thanks! Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Logan
Hi Bjorn,
I love your patch! Perhaps something to improve:
[auto build test WARNING on helgaas-pci/next]
[also build test WARNING on helgaas-pci/for-linus linus/master v6.1 next-20221216]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bjorn-Helgaas/PCI-switchtec-Trivial-cleanups/20221217-002341
base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
patch link: https://lore.kernel.org/r/20221216162126.207863-3-helgaas%40kernel.org
patch subject: [PATCH v2 2/2] PCI: switchtec: Return -EFAULT for copy_to_user() errors
config: x86_64-allyesconfig
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/a598bd934af2ccce340a59da1d10a3959b085dd0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Bjorn-Helgaas/PCI-switchtec-Trivial-cleanups/20221217-002341
git checkout a598bd934af2ccce340a59da1d10a3959b085dd0
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/pci/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/pci/switch/switchtec.c: In function 'switchtec_dev_read':
>> drivers/pci/switch/switchtec.c:623:1: warning: label 'out' defined but not used [-Wunused-label]
623 | out:
| ^~~
vim +/out +623 drivers/pci/switch/switchtec.c
080b47def5e5e2 Logan Gunthorpe 2017-03-06 557
080b47def5e5e2 Logan Gunthorpe 2017-03-06 558 static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
080b47def5e5e2 Logan Gunthorpe 2017-03-06 559 size_t size, loff_t *off)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 560 {
080b47def5e5e2 Logan Gunthorpe 2017-03-06 561 struct switchtec_user *stuser = filp->private_data;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 562 struct switchtec_dev *stdev = stuser->stdev;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 563 int rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 564
080b47def5e5e2 Logan Gunthorpe 2017-03-06 565 if (size < sizeof(stuser->cmd) ||
080b47def5e5e2 Logan Gunthorpe 2017-03-06 566 size > sizeof(stuser->cmd) + sizeof(stuser->data))
080b47def5e5e2 Logan Gunthorpe 2017-03-06 567 return -EINVAL;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 568
080b47def5e5e2 Logan Gunthorpe 2017-03-06 569 rc = lock_mutex_and_test_alive(stdev);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 570 if (rc)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 571 return rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 572
080b47def5e5e2 Logan Gunthorpe 2017-03-06 573 if (stuser->state == MRPC_IDLE) {
080b47def5e5e2 Logan Gunthorpe 2017-03-06 574 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 575 return -EBADE;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 576 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 577
080b47def5e5e2 Logan Gunthorpe 2017-03-06 578 stuser->read_len = size - sizeof(stuser->return_code);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 579
080b47def5e5e2 Logan Gunthorpe 2017-03-06 580 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 581
080b47def5e5e2 Logan Gunthorpe 2017-03-06 582 if (filp->f_flags & O_NONBLOCK) {
deaa0a8a74d865 Sebastian Andrzej Siewior 2020-03-21 583 if (!stuser->cmd_done)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 584 return -EAGAIN;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 585 } else {
deaa0a8a74d865 Sebastian Andrzej Siewior 2020-03-21 586 rc = wait_event_interruptible(stuser->cmd_comp,
deaa0a8a74d865 Sebastian Andrzej Siewior 2020-03-21 587 stuser->cmd_done);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 588 if (rc < 0)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 589 return rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 590 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 591
080b47def5e5e2 Logan Gunthorpe 2017-03-06 592 rc = lock_mutex_and_test_alive(stdev);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 593 if (rc)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 594 return rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 595
1a323bd071dd81 Kelvin Cao 2021-10-14 596 if (stuser->state == MRPC_IO_ERROR) {
1a323bd071dd81 Kelvin Cao 2021-10-14 597 mutex_unlock(&stdev->mrpc_mutex);
1a323bd071dd81 Kelvin Cao 2021-10-14 598 return -EIO;
1a323bd071dd81 Kelvin Cao 2021-10-14 599 }
1a323bd071dd81 Kelvin Cao 2021-10-14 600
080b47def5e5e2 Logan Gunthorpe 2017-03-06 601 if (stuser->state != MRPC_DONE) {
080b47def5e5e2 Logan Gunthorpe 2017-03-06 602 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 603 return -EBADE;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 604 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 605
080b47def5e5e2 Logan Gunthorpe 2017-03-06 606 rc = copy_to_user(data, &stuser->return_code,
080b47def5e5e2 Logan Gunthorpe 2017-03-06 607 sizeof(stuser->return_code));
080b47def5e5e2 Logan Gunthorpe 2017-03-06 608 if (rc) {
a598bd934af2cc Bjorn Helgaas 2022-12-16 609 mutex_unlock(&stdev->mrpc_mutex);
a598bd934af2cc Bjorn Helgaas 2022-12-16 610 return -EFAULT;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 611 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 612
080b47def5e5e2 Logan Gunthorpe 2017-03-06 613 data += sizeof(stuser->return_code);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 614 rc = copy_to_user(data, &stuser->data,
080b47def5e5e2 Logan Gunthorpe 2017-03-06 615 size - sizeof(stuser->return_code));
080b47def5e5e2 Logan Gunthorpe 2017-03-06 616 if (rc) {
a598bd934af2cc Bjorn Helgaas 2022-12-16 617 mutex_unlock(&stdev->mrpc_mutex);
a598bd934af2cc Bjorn Helgaas 2022-12-16 618 return -EFAULT;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 619 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 620
080b47def5e5e2 Logan Gunthorpe 2017-03-06 621 stuser_set_state(stuser, MRPC_IDLE);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 622
080b47def5e5e2 Logan Gunthorpe 2017-03-06 @623 out:
080b47def5e5e2 Logan Gunthorpe 2017-03-06 624 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 625
551ec658b69807 Kelvin Cao 2021-10-14 626 if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE ||
551ec658b69807 Kelvin Cao 2021-10-14 627 stuser->status == SWITCHTEC_MRPC_STATUS_ERROR)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 628 return size;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 629 else if (stuser->status == SWITCHTEC_MRPC_STATUS_INTERRUPTED)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 630 return -ENXIO;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 631 else
080b47def5e5e2 Logan Gunthorpe 2017-03-06 632 return -EBADMSG;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 633 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 634
Hi Bjorn,
I love your patch! Perhaps something to improve:
[auto build test WARNING on helgaas-pci/next]
[also build test WARNING on linus/master v6.1 next-20221216]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Bjorn-Helgaas/PCI-switchtec-Trivial-cleanups/20221217-002341
base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
patch link: https://lore.kernel.org/r/20221216162126.207863-3-helgaas%40kernel.org
patch subject: [PATCH v2 2/2] PCI: switchtec: Return -EFAULT for copy_to_user() errors
config: i386-randconfig-a004
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/a598bd934af2ccce340a59da1d10a3959b085dd0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Bjorn-Helgaas/PCI-switchtec-Trivial-cleanups/20221217-002341
git checkout a598bd934af2ccce340a59da1d10a3959b085dd0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/pci/switch/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> drivers/pci/switch/switchtec.c:623:1: warning: unused label 'out' [-Wunused-label]
out:
^~~~
1 warning generated.
vim +/out +623 drivers/pci/switch/switchtec.c
080b47def5e5e2 Logan Gunthorpe 2017-03-06 557
080b47def5e5e2 Logan Gunthorpe 2017-03-06 558 static ssize_t switchtec_dev_read(struct file *filp, char __user *data,
080b47def5e5e2 Logan Gunthorpe 2017-03-06 559 size_t size, loff_t *off)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 560 {
080b47def5e5e2 Logan Gunthorpe 2017-03-06 561 struct switchtec_user *stuser = filp->private_data;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 562 struct switchtec_dev *stdev = stuser->stdev;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 563 int rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 564
080b47def5e5e2 Logan Gunthorpe 2017-03-06 565 if (size < sizeof(stuser->cmd) ||
080b47def5e5e2 Logan Gunthorpe 2017-03-06 566 size > sizeof(stuser->cmd) + sizeof(stuser->data))
080b47def5e5e2 Logan Gunthorpe 2017-03-06 567 return -EINVAL;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 568
080b47def5e5e2 Logan Gunthorpe 2017-03-06 569 rc = lock_mutex_and_test_alive(stdev);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 570 if (rc)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 571 return rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 572
080b47def5e5e2 Logan Gunthorpe 2017-03-06 573 if (stuser->state == MRPC_IDLE) {
080b47def5e5e2 Logan Gunthorpe 2017-03-06 574 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 575 return -EBADE;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 576 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 577
080b47def5e5e2 Logan Gunthorpe 2017-03-06 578 stuser->read_len = size - sizeof(stuser->return_code);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 579
080b47def5e5e2 Logan Gunthorpe 2017-03-06 580 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 581
080b47def5e5e2 Logan Gunthorpe 2017-03-06 582 if (filp->f_flags & O_NONBLOCK) {
deaa0a8a74d865 Sebastian Andrzej Siewior 2020-03-21 583 if (!stuser->cmd_done)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 584 return -EAGAIN;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 585 } else {
deaa0a8a74d865 Sebastian Andrzej Siewior 2020-03-21 586 rc = wait_event_interruptible(stuser->cmd_comp,
deaa0a8a74d865 Sebastian Andrzej Siewior 2020-03-21 587 stuser->cmd_done);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 588 if (rc < 0)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 589 return rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 590 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 591
080b47def5e5e2 Logan Gunthorpe 2017-03-06 592 rc = lock_mutex_and_test_alive(stdev);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 593 if (rc)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 594 return rc;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 595
1a323bd071dd81 Kelvin Cao 2021-10-14 596 if (stuser->state == MRPC_IO_ERROR) {
1a323bd071dd81 Kelvin Cao 2021-10-14 597 mutex_unlock(&stdev->mrpc_mutex);
1a323bd071dd81 Kelvin Cao 2021-10-14 598 return -EIO;
1a323bd071dd81 Kelvin Cao 2021-10-14 599 }
1a323bd071dd81 Kelvin Cao 2021-10-14 600
080b47def5e5e2 Logan Gunthorpe 2017-03-06 601 if (stuser->state != MRPC_DONE) {
080b47def5e5e2 Logan Gunthorpe 2017-03-06 602 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 603 return -EBADE;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 604 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 605
080b47def5e5e2 Logan Gunthorpe 2017-03-06 606 rc = copy_to_user(data, &stuser->return_code,
080b47def5e5e2 Logan Gunthorpe 2017-03-06 607 sizeof(stuser->return_code));
080b47def5e5e2 Logan Gunthorpe 2017-03-06 608 if (rc) {
a598bd934af2cc Bjorn Helgaas 2022-12-16 609 mutex_unlock(&stdev->mrpc_mutex);
a598bd934af2cc Bjorn Helgaas 2022-12-16 610 return -EFAULT;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 611 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 612
080b47def5e5e2 Logan Gunthorpe 2017-03-06 613 data += sizeof(stuser->return_code);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 614 rc = copy_to_user(data, &stuser->data,
080b47def5e5e2 Logan Gunthorpe 2017-03-06 615 size - sizeof(stuser->return_code));
080b47def5e5e2 Logan Gunthorpe 2017-03-06 616 if (rc) {
a598bd934af2cc Bjorn Helgaas 2022-12-16 617 mutex_unlock(&stdev->mrpc_mutex);
a598bd934af2cc Bjorn Helgaas 2022-12-16 618 return -EFAULT;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 619 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 620
080b47def5e5e2 Logan Gunthorpe 2017-03-06 621 stuser_set_state(stuser, MRPC_IDLE);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 622
080b47def5e5e2 Logan Gunthorpe 2017-03-06 @623 out:
080b47def5e5e2 Logan Gunthorpe 2017-03-06 624 mutex_unlock(&stdev->mrpc_mutex);
080b47def5e5e2 Logan Gunthorpe 2017-03-06 625
551ec658b69807 Kelvin Cao 2021-10-14 626 if (stuser->status == SWITCHTEC_MRPC_STATUS_DONE ||
551ec658b69807 Kelvin Cao 2021-10-14 627 stuser->status == SWITCHTEC_MRPC_STATUS_ERROR)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 628 return size;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 629 else if (stuser->status == SWITCHTEC_MRPC_STATUS_INTERRUPTED)
080b47def5e5e2 Logan Gunthorpe 2017-03-06 630 return -ENXIO;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 631 else
080b47def5e5e2 Logan Gunthorpe 2017-03-06 632 return -EBADMSG;
080b47def5e5e2 Logan Gunthorpe 2017-03-06 633 }
080b47def5e5e2 Logan Gunthorpe 2017-03-06 634
diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c index d7ae84070e29..0ac9d4488210 100644 --- a/drivers/pci/switch/switchtec.c +++ b/drivers/pci/switch/switchtec.c @@ -606,16 +606,16 @@ static ssize_t switchtec_dev_read(struct file *filp, char __user *data, rc = copy_to_user(data, &stuser->return_code, sizeof(stuser->return_code)); if (rc) { - rc = -EFAULT; - goto out; + mutex_unlock(&stdev->mrpc_mutex); + return -EFAULT; } data += sizeof(stuser->return_code); rc = copy_to_user(data, &stuser->data, size - sizeof(stuser->return_code)); if (rc) { - rc = -EFAULT; - goto out; + mutex_unlock(&stdev->mrpc_mutex); + return -EFAULT; } stuser_set_state(stuser, MRPC_IDLE);