stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Sifan Naeem <sifan.naeem@imgtec.com>,
	Mark Brown <broonie@kernel.org>
Subject: [PATCH 4.1 046/102] spi: img-spfi: fix multiple calls to request gpio
Date: Sat, 19 Sep 2015 10:27:58 -0700	[thread overview]
Message-ID: <20150919171747.540979971@linuxfoundation.org> (raw)
In-Reply-To: <20150919171745.474069671@linuxfoundation.org>

4.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Sifan Naeem <sifan.naeem@imgtec.com>

commit b03ba9e314c12b2127243145b5c1f41b2408de62 upstream.

spfi_setup may be called many times by the spi framework, but
gpio_request_one can only be called once without freeing, repeatedly
calling gpio_request_one will cause an error to be thrown, which
causes the request to spi_setup to be marked as failed.

We can have a per-spi_device flag that indicates whether or not the
gpio has been requested. If the gpio has already been requested use
gpio_direction_output to set the direction of the gpio.

Fixes: 8c2c8c03cdcb ("spi: img-spfi: Control CS lines with GPIO")
Signed-off-by: Sifan Naeem <sifan.naeem@imgtec.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/spi/spi-img-spfi.c |   47 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 7 deletions(-)

--- a/drivers/spi/spi-img-spfi.c
+++ b/drivers/spi/spi-img-spfi.c
@@ -105,6 +105,10 @@ struct img_spfi {
 	bool rx_dma_busy;
 };
 
+struct img_spfi_device_data {
+	bool gpio_requested;
+};
+
 static inline u32 spfi_readl(struct img_spfi *spfi, u32 reg)
 {
 	return readl(spfi->regs + reg);
@@ -441,20 +445,49 @@ static int img_spfi_unprepare(struct spi
 static int img_spfi_setup(struct spi_device *spi)
 {
 	int ret;
+	struct img_spfi_device_data *spfi_data = spi_get_ctldata(spi);
 
-	ret = gpio_request_one(spi->cs_gpio, (spi->mode & SPI_CS_HIGH) ?
-			       GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
-			       dev_name(&spi->dev));
-	if (ret)
-		dev_err(&spi->dev, "can't request chipselect gpio %d\n",
+	if (!spfi_data) {
+		spfi_data = kzalloc(sizeof(*spfi_data), GFP_KERNEL);
+		if (!spfi_data)
+			return -ENOMEM;
+		spfi_data->gpio_requested = false;
+		spi_set_ctldata(spi, spfi_data);
+	}
+	if (!spfi_data->gpio_requested) {
+		ret = gpio_request_one(spi->cs_gpio,
+				       (spi->mode & SPI_CS_HIGH) ?
+				       GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
+				       dev_name(&spi->dev));
+		if (ret)
+			dev_err(&spi->dev, "can't request chipselect gpio %d\n",
 				spi->cs_gpio);
-
+		else
+			spfi_data->gpio_requested = true;
+	} else {
+		if (gpio_is_valid(spi->cs_gpio)) {
+			int mode = ((spi->mode & SPI_CS_HIGH) ?
+				    GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH);
+
+			ret = gpio_direction_output(spi->cs_gpio, mode);
+			if (ret)
+				dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n",
+					spi->cs_gpio, ret);
+		}
+	}
 	return ret;
 }
 
 static void img_spfi_cleanup(struct spi_device *spi)
 {
-	gpio_free(spi->cs_gpio);
+	struct img_spfi_device_data *spfi_data = spi_get_ctldata(spi);
+
+	if (spfi_data) {
+		if (spfi_data->gpio_requested)
+			gpio_free(spi->cs_gpio);
+		kfree(spfi_data);
+		spi_set_ctldata(spi, NULL);
+	}
 }
 
 static void img_spfi_config(struct spi_master *master, struct spi_device *spi,



  parent reply	other threads:[~2015-09-19 17:30 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19 17:27 [PATCH 4.1 000/102] 4.1.8-stable review Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 001/102] x86/ldt: Make modify_ldt synchronous Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 002/102] x86/ldt: Correct LDT access in single stepping logic Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 003/102] x86/ldt: Correct FPU emulation access to LDT Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 004/102] x86/ldt: Further fix FPU emulation Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 005/102] DRM - radeon: Dont link train DisplayPort on HPD until we get the dpcd Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 006/102] drm/i915: apply the PCI_D0/D3 hibernation workaround everywhere on pre GEN6 Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 010/102] drm/radeon: fix HDMI quantization_range for pre-DCE5 asics Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 011/102] drm/i915: Preserve SSC earlier Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 012/102] drm/qxl: validate monitors config modes Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 016/102] s390/sclp: fix compile error Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 017/102] s390/setup: fix novx parameter Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 018/102] iio: bmg160: IIO_BUFFER and IIO_TRIGGERED_BUFFER are required Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 019/102] iio: event: Remove negative error code from iio_event_poll Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 020/102] iio: industrialio-buffer: Fix iio_buffer_poll return value Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 021/102] iio: adis16400: Fix adis16448 gyroscope scale Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 022/102] iio: Add inverse unit conversion macros Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 023/102] iio: adis16480: Fix scale factors Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 025/102] staging: comedi: adl_pci7x3x: fix digital output on PCI-7230 Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 026/102] staging: comedi: usbduxsigma: dont clobber ai_timer in command test Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 027/102] staging: comedi: usbduxsigma: dont clobber ao_timer " Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 028/102] PM / clk: dont return int on __pm_clk_enable() Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 029/102] clk: rockchip: rk3288: add CLK_SET_RATE_PARENT to sclk_mac Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 030/102] clk: exynos4: Fix wrong clock for Exynos4x12 ADC Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 031/102] clk: s5pv210: add missing call to samsung_clk_of_add_provider() Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 032/102] clk: pistachio: Fix override of clk-pll settings from boot loader Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 033/102] clk: pistachio: correct critical clock list Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 034/102] clk: versatile: off by one in clk_sp810_timerclken_of_get() Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 035/102] clk: pxa: fix core frequency reporting unit Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 036/102] clk: qcom: Set CLK_SET_RATE_PARENT on ce1 clocks Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 037/102] clk: qcom: Fix MSM8916 prng clock enable bit Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 038/102] PCI: Fix TI816X class code quirk Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 039/102] PCI: Add dev_flags bit to access VPD through function 0 Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 040/102] PCI: Add VPD function 0 quirk for Intel Ethernet devices Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 041/102] PCI: Disable async suspend/resume for JMicron multi-function SATA/AHCI Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 042/102] spi: bcm2835: set up spi-mode before asserting cs-gpio Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 043/102] spi: Fix regression in spi-bitbang-txrx.h Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 044/102] spi: sh-msiof: Fix FIFO size to 64 word from 256 word Greg Kroah-Hartman
2015-09-19 17:27 ` [PATCH 4.1 045/102] spi: img-spfi: check for timeout error before proceeding Greg Kroah-Hartman
2015-09-19 17:27 ` Greg Kroah-Hartman [this message]
2015-09-19 17:27 ` [PATCH 4.1 047/102] spi: img-spfi: fix kbuild test robot warning Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 048/102] spi: dw: Allow interface drivers to limit data I/O to word sizes Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 049/102] USB: symbolserial: Use usb_get_serial_port_data Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 050/102] USB: qcserial: add HP lt4111 LTE/EV-DO/HSPA+ Gobi 4G Module Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 051/102] USB: ftdi_sio: Added custom PID for CustomWare products Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 052/102] USB: pl2303: fix baud-rate divisor calculations Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 053/102] libxfs: readahead of dir3 data blocks should use the read verifier Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 054/102] xfs: Fix xfs_attr_leafblock definition Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 055/102] xfs: Fix file type directory corruption for btree directories Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 056/102] usb: gadget: m66592-udc: forever loop in set_feature() Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 057/102] doc: usb: gadget-testing: using the updated testusb.c Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 058/102] usb: dwc3: ep0: Fix mem corruption on OUT transfers of more than 512 bytes Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 059/102] usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 060/102] usb: host: ehci-sys: delete useless bus_to_hcd conversion Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 061/102] tty: serial: men_z135_uart.c: Fix race between IRQ and set_termios() Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 062/102] ASoC: rt5640: fix line out no sound issue Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 063/102] ASoC: samsung: Remove redundant arndale_audio_remove Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 064/102] ASoC: adav80x: Remove .read_flag_mask setting from adav80x_regmap_config Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 065/102] ASoC: arizona: Fix gain settings of FLL in free-run mode Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 066/102] ASoC: arizona: Poll for FLL clock OK rather than use interrupts Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 067/102] serial: 8250: dont bind to SMSC IrCC IR port Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 068/102] serial: 8250: bind to ALi Fast Infrared Controller (ALI5123) Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 069/102] serial: 8250_pci: Add support for Pericom PI7C9X795[1248] Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 070/102] serial: samsung: fix DMA mode enter condition for small FIFO sizes Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 071/102] serial: samsung: fix DMA for FIFO smaller than cache line size Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 072/102] crypto: vmx - Fixing GHASH Key issue on little endian Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 073/102] crypto: ghash-clmulni: specify context size for ghash async algorithm Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 074/102] HID: usbhid: Fix the check for HID_RESET_PENDING in hid_io_error Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 075/102] HID: cp2112: fix byte order in SMBUS operations Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 076/102] HID: cp2112: fix I2C_SMBUS_BYTE write Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 077/102] KVM: MMU: fix validation of mmio page fault Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 078/102] KVM: PPC: Book3S HV: Exit on H_DOORBELL if HOST_IPI is set Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 079/102] KVM: PPC: Book3S HV: Fix race in reading change bit when removing HPTE Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 080/102] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 081/102] xtensa: fix threadptr reload on return to userspace Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 082/102] xtensa: fix kernel register spilling Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 083/102] devres: fix devres_get() Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 084/102] Doc: ABI: testing: configfs-usb-gadget-loopback Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 085/102] Doc: ABI: testing: configfs-usb-gadget-sourcesink Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 086/102] spi/spi-xilinx: Fix spurious IRQ ACK on irq mode Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 087/102] spi/spi-xilinx: Fix mixed poll/irq mode Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 088/102] auxdisplay: ks0108: fix refcount Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 089/102] regulator: pbias: Fix broken pbias disable functionality Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 090/102] x86/mce: Reenable CMCI banks when swiching back to interrupt mode Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 091/102] soc/tegra: pmc: Avoid usage of uninitialized variable Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 092/102] of/address: Dont loop forever in of_find_matching_node_by_address() Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 093/102] ARM: orion5x: fix legacy orion5x IRQ numbers Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 094/102] ARM: dts: fix clock-frequency of display timing0 for exynos3250-rinato Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 095/102] ARM: OMAP2+: DRA7: clockdomain: change l4per2_7xx_clkdm to SW_WKUP Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 096/102] ARM: rockchip: fix the CPU soft reset Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 097/102] ARM: dts: rockchip: fix rk3288 watchdog irq Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 098/102] ACPI, PCI: Penalize legacy IRQ used by ACPI SCI Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 099/102] drivercore: Fix unregistration path of platform devices Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 100/102] fs: Set the size of empty dirs to 0 Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 101/102] hpfs: update ctime and mtime on directory modification Greg Kroah-Hartman
2015-09-19 17:28 ` [PATCH 4.1 102/102] fs: create and use seq_show_option for escaping Greg Kroah-Hartman
2015-09-19 20:38 ` [PATCH 4.1 000/102] 4.1.8-stable review Guenter Roeck
2015-09-20  0:25 ` Guenter Roeck
2015-09-20  5:28   ` Willy Tarreau
2015-09-20  7:51     ` Sudip Mukherjee
2015-09-21  1:36     ` Greg Kroah-Hartman
2015-09-21  5:42 ` Sudip Mukherjee
2015-09-21 16:22 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150919171747.540979971@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sifan.naeem@imgtec.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).