From patchwork Thu Aug 24 16:22:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 717374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BC9BC3DA6F for ; Thu, 24 Aug 2023 16:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242499AbjHXQYI (ORCPT ); Thu, 24 Aug 2023 12:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242502AbjHXQXn (ORCPT ); Thu, 24 Aug 2023 12:23:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E88501BE; Thu, 24 Aug 2023 09:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692894221; x=1724430221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q9V0U1YKW0QwosCD9F4IkgFyJi6mucyN+dXeisMRhkU=; b=dJaAmeunr8JFWVP1uR351PsXn3aarn6kU/I+rs4iD+/s7F8sMt2SjsQL MzAW5pWFHFnNWM19pKCpjkocLAhKr3pPkGr+mY0ZK5DnwT75zn9oxSjtf q7lQcIjB2H7VjaDsyR5ZWV9TNsw38CNZSMb5KKf0x/0YkO+pcr0W021og 8irW/nek8/rNp2E+NV6E/IKDyJfOVOVe6q62juxZBmGOwktpu82h56EXc EcoYavTJjTQwn0Jt9QnqRj0FIrrT6StoXqljhB9XHQvo6tXhGYNuSp8Jk iVMRNsaMZHE2paOWMo6BsA46WWZyIV+JzPLlswxDSZqwSeYrtUePs8H06 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="377235994" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="377235994" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 09:22:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="851582219" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="851582219" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 24 Aug 2023 09:22:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D6B3768; Thu, 24 Aug 2023 19:22:13 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexander Sverdlin , Andy Shevchenko Subject: [PATCH v1 1/3] spidev: Decrease indentation level in spidev_ioctl() SPI_IOC_RD_MODE* Date: Thu, 24 Aug 2023 19:22:07 +0300 Message-Id: <20230824162209.2890440-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230824162209.2890440-1-andriy.shevchenko@linux.intel.com> References: <20230824162209.2890440-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Instead of defining a local controller variable inside an indented block, move the definition to the top of spidev_ioctl() and reuse it in the SPI_IOC_RD_MODE* and SPI_IOC_WR_MODE* cases. This drops unneeded indentation and reduces amount of LoCs. Signed-off-by: Andy Shevchenko --- drivers/spi/spidev.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index d13dc15cc191..dc516f0ca71f 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -357,6 +357,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) int retval = 0; struct spidev_data *spidev; struct spi_device *spi; + struct spi_controller *ctlr; u32 tmp; unsigned n_ioc; struct spi_ioc_transfer *ioc; @@ -376,6 +377,8 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return -ESHUTDOWN; } + ctlr = spi->controller; + /* use the buffer lock here for triple duty: * - prevent I/O (from us) so calling spi_setup() is safe; * - prevent concurrent SPI_IOC_WR_* from morphing @@ -390,13 +393,9 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case SPI_IOC_RD_MODE32: tmp = spi->mode; - { - struct spi_controller *ctlr = spi->controller; - - if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && - ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]) - tmp &= ~SPI_CS_HIGH; - } + if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && + ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]) + tmp &= ~SPI_CS_HIGH; if (cmd == SPI_IOC_RD_MODE) retval = put_user(tmp & SPI_MODE_MASK, @@ -424,7 +423,6 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) else retval = get_user(tmp, (u32 __user *)arg); if (retval == 0) { - struct spi_controller *ctlr = spi->controller; u32 save = spi->mode; if (tmp & ~SPI_MODE_MASK) { From patchwork Thu Aug 24 16:22:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 716818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1966C71153 for ; Thu, 24 Aug 2023 16:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242494AbjHXQYH (ORCPT ); Thu, 24 Aug 2023 12:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242500AbjHXQXm (ORCPT ); Thu, 24 Aug 2023 12:23:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 179FE1736; Thu, 24 Aug 2023 09:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692894221; x=1724430221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ax0zHaeo1VbO9tta1swVNEvMf/cRovUF7DQd8Gh1DLo=; b=XflR0nA8kfstZBWi/XIKWg1UKTbtRexw205bEKucbhDGifqxKy7Jsiaq 0+FS7PplDGBfwxkxGerI/ZSosFl6c+9Gn2sU6URQtP65k1H9WRzwprVfq K96S83rloAY6ZRBg/NzcbAS7aMbmU8LiCpKACqo/boneCChBaIh/x+0OM EGgZjHnPj55tQwN6ZPsVWLxLoGTi0Ye/Va8oWWE/YnQB+Hdu0THyYFNdn BfIenw70P+bjV4TnmZdlxonjqmLjOx6pj+taEemyPiojlQ137ygeEangR IAtAFvOce4T2oEmitHWurm3HHWasBbElqvhKHxRXwhjp7ZJDR/XpOQipR g==; X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="377235990" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="377235990" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 09:22:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="851582218" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="851582218" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 24 Aug 2023 09:22:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E528E1CA; Thu, 24 Aug 2023 19:22:13 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexander Sverdlin , Andy Shevchenko Subject: [PATCH v1 2/3] spidev: Switch to use spi_get_csgpiod() Date: Thu, 24 Aug 2023 19:22:08 +0300 Message-Id: <20230824162209.2890440-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230824162209.2890440-1-andriy.shevchenko@linux.intel.com> References: <20230824162209.2890440-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org spidev_ioctl() checks if there is an SPI chip select is driven by GPIO. Instead of current code, we can call spi_get_csgpiod(). Signed-off-by: Andy Shevchenko Reviewed-by: Alexander Sverdlin --- drivers/spi/spidev.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index dc516f0ca71f..e324b42c658c 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -393,8 +393,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case SPI_IOC_RD_MODE32: tmp = spi->mode; - if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && - ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]) + if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0)) tmp &= ~SPI_CS_HIGH; if (cmd == SPI_IOC_RD_MODE) @@ -430,8 +429,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; } - if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && - ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]) + if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0)) tmp |= SPI_CS_HIGH; tmp |= spi->mode & ~SPI_MODE_MASK; From patchwork Thu Aug 24 16:22:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 717375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AECDBC6FA8F for ; Thu, 24 Aug 2023 16:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242481AbjHXQXe (ORCPT ); Thu, 24 Aug 2023 12:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242483AbjHXQXN (ORCPT ); Thu, 24 Aug 2023 12:23:13 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ED0619AC; Thu, 24 Aug 2023 09:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692894192; x=1724430192; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JFT3ymVXjR1RLSxdJttkiZY5DC9NsR7CjrAq8kMVtrg=; b=ht9dsrw08+rb4YcivnfjxvswRz8maXsoFTVjkeYGTNJmm9No6OxuPYAg Vpdv/ZglEWZvN89nU5p5zd7EEzCDJq8cLXXFQlc7tBQWr62ZymEV7j9rs HfaB3Xe/yeQy8X5wtWnxZOzb7iefKbQvDIdsPnuNBWTrCNuTZpXGPZG9W 0OGXvmuqGyM3orf8mxDjDequurfXeAGDB5Zt1Aa66XtBiGME0si5vXQCK KIxlr0swMXKknMZzx7U/6YFWWK+EFG6Ke1WHJ+TGoMaZIUQozO0hfRUYN EIAaLBQhS9hG44P3qG8EXu1ZiREJNW4wETWK1z5WGG6Vlcse+9V7iy/bv g==; X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="359487450" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="359487450" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 09:22:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10812"; a="766599817" X-IronPort-AV: E=Sophos;i="6.02,195,1688454000"; d="scan'208";a="766599817" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 24 Aug 2023 09:22:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id F390924C; Thu, 24 Aug 2023 19:22:13 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexander Sverdlin , Andy Shevchenko , Lukas Wunner Subject: [PATCH v1 3/3] spidev: Simplify SPI_IOC_RD_MODE* cases in spidev_ioctl() Date: Thu, 24 Aug 2023 19:22:09 +0300 Message-Id: <20230824162209.2890440-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230824162209.2890440-1-andriy.shevchenko@linux.intel.com> References: <20230824162209.2890440-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The temporary variable tmp is not used outside of the SPI_IOC_RD_MODE* cases, hence we can optimize its use. Signed-off-by: Andy Shevchenko Reviewed-by: Lukas Wunner --- drivers/spi/spidev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index e324b42c658c..c5450217528b 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -391,17 +391,15 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) /* read requests */ case SPI_IOC_RD_MODE: case SPI_IOC_RD_MODE32: - tmp = spi->mode; + tmp = spi->mode & SPI_MODE_MASK; if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0)) tmp &= ~SPI_CS_HIGH; if (cmd == SPI_IOC_RD_MODE) - retval = put_user(tmp & SPI_MODE_MASK, - (__u8 __user *)arg); + retval = put_user(tmp, (__u8 __user *)arg); else - retval = put_user(tmp & SPI_MODE_MASK, - (__u32 __user *)arg); + retval = put_user(tmp, (__u32 __user *)arg); break; case SPI_IOC_RD_LSB_FIRST: retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,