Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17519892ybl; Thu, 2 Jan 2020 07:02:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwXThhBGZAgy9dXtl5cBYKp4F6//sVPX2cEYQbtgcoq3l+SPqCMa6HdgPo5Zkh8WbQ3c5UY X-Received: by 2002:a9d:600e:: with SMTP id h14mr89768359otj.113.1577977324494; Thu, 02 Jan 2020 07:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577977324; cv=none; d=google.com; s=arc-20160816; b=zBp/POoECuoBYziZIX6V3Swek6oQZIl/1CShd3nUpBGE8qO7aDFiI49sQaDx22DwtJ 9j26u99cmOmwRwP7Hh/MCm6VriVET3tfuhX7eHQrRYV9RnijpgsE2H71QrHyNr9emBoN SQ4tJAMd2kDEi/hpXrCoBGxunWsToI5G8nbKoqt3Ad6f6oqQKBpQFWQI3i0RLop3Wu59 3lVghLLXgzcAvME7FtcetJRjm1nxW8J/rSrDM7xTwYGj0xqRuvkgufKZ7N6vKoZdcmO4 AIE23HmwxAQDPMhrTZZHRQn8zlXP9JCa5KlpuB5y8R70pa2HpkLL3R7Dzgu9HQF/EQsa 6YCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bSMoH68OJuS2SiyqIA0a/D4rZaEt5209rKVTqBaz+Zw=; b=UfTIhw8xCk9od8kZPbSTRGfVVTpG0/5J8nmRtpb069d5DFGqj7fQbYqBiOjJ4E9IYw c1bXtKJBUlVTZZqMgD2BC3sPQ0tdMMbS1T1nq7VAAdWkrJUTjQnNaN7k0dCUqIXmxxpR vgoPRxCHZyQUsbxyR1d6/d20+7KTjjfjcs4X7VfdPsyZMa2Z//xS4lSsLM+hCBCFwiLn D3PY8tQqzQrJ95pCdmFrmc660vOd/AOuR3Z4iDI64oSwZcHHliMeKC7eoGtIgs6rP3LA qe4jk8VnJ5t63rFHBqhHsvymwdaRRIcbO2436sMqEuVFzAxTPPfelTitnhR7tusiU2F0 BBqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si6784260otc.160.2020.01.02.07.01.52; Thu, 02 Jan 2020 07:02:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728619AbgABPBA (ORCPT + 99 others); Thu, 2 Jan 2020 10:01:00 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:37957 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbgABPBA (ORCPT ); Thu, 2 Jan 2020 10:01:00 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1MrhDg-1jYVqE2Tga-00ndiR; Thu, 02 Jan 2020 16:00:06 +0100 From: Arnd Bergmann To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 10/22] compat_ioctl: add scsi_compat_ioctl Date: Thu, 2 Jan 2020 15:55:28 +0100 Message-Id: <20200102145552.1853992-11-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20200102145552.1853992-1-arnd@arndb.de> References: <20200102145552.1853992-1-arnd@arndb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6w7 EacpwBCCiboM8Sy7b0IVCW3gLrr1lv12xD0zkUxfE27z4luCSOJqN0lN12X6iabUGs6jTD/2R w18vc/UUpTfk3AES8Lf1FJzzbPkkxqpNPvZM8pN8cYWryKi4+jbEdamlKtwsmggOZHKiWdRWW YkGNaEthjv6Z041GvVRQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to move the compat handling for SCSI ioctl commands out of fs/compat_ioctl.c into the individual drivers, we need a helper function first to match the native ioctl handler called by sd, sr, st, etc. Signed-off-by: Arnd Bergmann --- drivers/scsi/scsi_ioctl.c | 54 +++++++++++++++++++++++++++++---------- include/scsi/scsi_ioctl.h | 1 + 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index 57bcd05605bf..8f3af87b6bb0 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c @@ -189,17 +189,7 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg) } -/** - * scsi_ioctl - Dispatch ioctl to scsi device - * @sdev: scsi device receiving ioctl - * @cmd: which ioctl is it - * @arg: data associated with ioctl - * - * Description: The scsi_ioctl() function differs from most ioctls in that it - * does not take a major/minor number as the dev field. Rather, it takes - * a pointer to a &struct scsi_device. - */ -int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +static int scsi_ioctl_common(struct scsi_device *sdev, int cmd, void __user *arg) { char scsi_cmd[MAX_COMMAND_SIZE]; struct scsi_sense_hdr sense_hdr; @@ -266,14 +256,50 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) return scsi_ioctl_get_pci(sdev, arg); case SG_SCSI_RESET: return scsi_ioctl_reset(sdev, arg); - default: - if (sdev->host->hostt->ioctl) - return sdev->host->hostt->ioctl(sdev, cmd, arg); } + return -ENOIOCTLCMD; +} + +/** + * scsi_ioctl - Dispatch ioctl to scsi device + * @sdev: scsi device receiving ioctl + * @cmd: which ioctl is it + * @arg: data associated with ioctl + * + * Description: The scsi_ioctl() function differs from most ioctls in that it + * does not take a major/minor number as the dev field. Rather, it takes + * a pointer to a &struct scsi_device. + */ +int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +{ + int ret = scsi_ioctl_common(sdev, cmd, arg); + + if (ret != -ENOIOCTLCMD) + return ret; + + if (sdev->host->hostt->ioctl) + return sdev->host->hostt->ioctl(sdev, cmd, arg); + return -EINVAL; } EXPORT_SYMBOL(scsi_ioctl); +#ifdef CONFIG_COMPAT +int scsi_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +{ + int ret = scsi_ioctl_common(sdev, cmd, arg); + + if (ret != -ENOIOCTLCMD) + return ret; + + if (sdev->host->hostt->compat_ioctl) + return sdev->host->hostt->compat_ioctl(sdev, cmd, arg); + + return ret; +} +EXPORT_SYMBOL(scsi_compat_ioctl); +#endif + /* * We can process a reset even when a device isn't fully operable. */ diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h index 5101e987c0ef..4fe69d863b5d 100644 --- a/include/scsi/scsi_ioctl.h +++ b/include/scsi/scsi_ioctl.h @@ -44,6 +44,7 @@ typedef struct scsi_fctargaddress { int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, int cmd, bool ndelay); extern int scsi_ioctl(struct scsi_device *, int, void __user *); +extern int scsi_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg); #endif /* __KERNEL__ */ #endif /* _SCSI_IOCTL_H */ -- 2.20.0