linux-kernel.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, Kent Gibson <warthog618@gmail.com>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.3 082/112] gpiolib: dont clear FLAG_IS_OUT when emulating open-drain/open-source
Date: Wed, 16 Oct 2019 14:51:14 -0700	[thread overview]
Message-ID: <20191016214904.700115170@linuxfoundation.org> (raw)
In-Reply-To: <20191016214844.038848564@linuxfoundation.org>

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

[ Upstream commit e735244e2cf068f98b6384681a38993e0517a838 ]

When emulating open-drain/open-source by not actively driving the output
lines - we're simply changing their mode to input. This is wrong as it
will then make it impossible to change the value of such line - it's now
considered to actually be in input mode. If we want to still use the
direction_input() callback for simplicity then we need to set FLAG_IS_OUT
manually in gpiod_direction_output() and not clear it in
gpio_set_open_drain_value_commit() and
gpio_set_open_source_value_commit().

Fixes: c663e5f56737 ("gpio: support native single-ended hardware drivers")
Cc: stable@vger.kernel.org
Reported-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
[Bartosz: backported to v5.3, v4.19]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpio/gpiolib.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2775,8 +2775,10 @@ int gpiod_direction_output(struct gpio_d
 		if (!ret)
 			goto set_output_value;
 		/* Emulate open drain by not actively driving the line high */
-		if (value)
-			return gpiod_direction_input(desc);
+		if (value) {
+			ret = gpiod_direction_input(desc);
+			goto set_output_flag;
+		}
 	}
 	else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
 		ret = gpio_set_config(gc, gpio_chip_hwgpio(desc),
@@ -2784,8 +2786,10 @@ int gpiod_direction_output(struct gpio_d
 		if (!ret)
 			goto set_output_value;
 		/* Emulate open source by not actively driving the line low */
-		if (!value)
-			return gpiod_direction_input(desc);
+		if (!value) {
+			ret = gpiod_direction_input(desc);
+			goto set_output_flag;
+		}
 	} else {
 		gpio_set_config(gc, gpio_chip_hwgpio(desc),
 				PIN_CONFIG_DRIVE_PUSH_PULL);
@@ -2793,6 +2797,17 @@ int gpiod_direction_output(struct gpio_d
 
 set_output_value:
 	return gpiod_direction_output_raw_commit(desc, value);
+
+set_output_flag:
+	/*
+	 * When emulating open-source or open-drain functionalities by not
+	 * actively driving the line (setting mode to input) we still need to
+	 * set the IS_OUT flag or otherwise we won't be able to set the line
+	 * value anymore.
+	 */
+	if (ret == 0)
+		set_bit(FLAG_IS_OUT, &desc->flags);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(gpiod_direction_output);
 
@@ -3153,8 +3168,6 @@ static void gpio_set_open_drain_value_co
 
 	if (value) {
 		err = chip->direction_input(chip, offset);
-		if (!err)
-			clear_bit(FLAG_IS_OUT, &desc->flags);
 	} else {
 		err = chip->direction_output(chip, offset, 0);
 		if (!err)
@@ -3184,8 +3197,6 @@ static void gpio_set_open_source_value_c
 			set_bit(FLAG_IS_OUT, &desc->flags);
 	} else {
 		err = chip->direction_input(chip, offset);
-		if (!err)
-			clear_bit(FLAG_IS_OUT, &desc->flags);
 	}
 	trace_gpio_direction(desc_to_gpio(desc), !value, err);
 	if (err < 0)



  parent reply	other threads:[~2019-10-16 22:04 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 21:49 [PATCH 5.3 000/112] 5.3.7-stable review Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 001/112] panic: ensure preemption is disabled during panic() Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 002/112] USB: rio500: Remove Rio 500 kernel driver Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 003/112] USB: yurex: Dont retry on unexpected errors Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 004/112] USB: yurex: fix NULL-derefs on disconnect Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 005/112] USB: usb-skeleton: fix runtime PM after driver unbind Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 006/112] USB: usb-skeleton: fix NULL-deref on disconnect Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 5.3 007/112] xhci: Fix false warning message about wrong bounce buffer write length Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 008/112] xhci: Prevent device initiated U1/U2 link pm if exit latency is too long Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 009/112] xhci: Check all endpoints for LPM timeout Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 010/112] xhci: Fix USB 3.1 capability detection on early xHCI 1.1 spec based hosts Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 011/112] usb: xhci: wait for CNR controller not ready bit in xhci resume Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 012/112] xhci: Prevent deadlock when xhci adapter breaks during init Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 013/112] xhci: Increase STS_SAVE timeout in xhci_suspend() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 014/112] xhci: Fix NULL pointer dereference in xhci_clear_tt_buffer_complete() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 015/112] USB: adutux: fix use-after-free on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 016/112] USB: adutux: fix NULL-derefs " Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 017/112] USB: adutux: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 018/112] USB: iowarrior: fix use-after-free on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 019/112] USB: iowarrior: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 020/112] USB: iowarrior: fix use-after-free after driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 021/112] USB: usblp: fix runtime PM " Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 022/112] USB: chaoskey: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 023/112] USB: ldusb: fix NULL-derefs on driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 024/112] serial: uartlite: fix exit path null pointer Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 025/112] serial: uartps: Fix uartps_major handling Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 026/112] USB: serial: keyspan: fix NULL-derefs on open() and write() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 027/112] USB: serial: ftdi_sio: add device IDs for Sienna and Echelon PL-20 Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 028/112] USB: serial: option: add Telit FN980 compositions Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 029/112] USB: serial: option: add support for Cinterion CLS8 devices Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 030/112] USB: serial: fix runtime PM after driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 031/112] USB: usblcd: fix I/O after disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 032/112] USB: microtek: fix info-leak at probe Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 033/112] USB: dummy-hcd: fix power budget for SuperSpeed mode Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 034/112] usb: renesas_usbhs: gadget: Do not discard queues in usb_ep_set_{halt,wedge}() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 035/112] usb: renesas_usbhs: gadget: Fix usb_ep_set_{halt,wedge}() behavior Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 036/112] usb: typec: tcpm: usb: typec: tcpm: Fix a signedness bug in tcpm_fw_get_caps() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 037/112] usb: typec: ucsi: ccg: Remove run_isr flag Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 038/112] usb: typec: ucsi: displayport: Fix for the mode entering routine Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 039/112] USB: legousbtower: fix slab info leak at probe Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 040/112] USB: legousbtower: fix deadlock on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 041/112] USB: legousbtower: fix potential NULL-deref " Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 042/112] USB: legousbtower: fix open after failed reset request Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 043/112] USB: legousbtower: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 044/112] mei: me: add comet point (lake) LP device ids Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 045/112] mei: avoid FW version request on Ibex Peak and earlier Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 046/112] gpio: eic: sprd: Fix the incorrect EIC offset when toggling Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 047/112] staging/fbtft: Depend on OF Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 048/112] staging: bcm2835-audio: Fix draining behavior regression Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 049/112] Staging: fbtft: fix memory leak in fbtft_framebuffer_alloc Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 050/112] staging: rtl8188eu: fix HighestRate check in odm_ARFBRefresh_8188E() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 051/112] staging: vt6655: Fix memory leak in vt6655_probe Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 052/112] iio: adc: hx711: fix bug in sampling of data Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 053/112] iio: adc: ad799x: fix probe error handling Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 054/112] iio: adc: axp288: Override TS pin bias current for some models Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 055/112] iio: adc: stm32-adc: move registers definitions Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 056/112] iio: adc: stm32-adc: fix a race when using several adcs with dma and irq Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 057/112] iio: light: opt3001: fix mutex unlock race Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 058/112] iio: light: add missing vcnl4040 of_compatible Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 059/112] iio: accel: adxl372: Fix/remove limitation for FIFO samples Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 060/112] iio: accel: adxl372: Fix push to buffers lost samples Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 061/112] iio: accel: adxl372: Perform a reset at start up Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 062/112] efivar/ssdt: Dont iterate over EFI vars if no SSDT override was specified Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 063/112] efi/tpm: Dont access event->count when it isnt mapped Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 064/112] efi/tpm: Dont traverse an event log with no events Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 065/112] efi/tpm: Only set efi_tpm_final_log_size after successful event log parsing Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 066/112] perf llvm: Dont access out-of-scope array Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 5.3 067/112] perf inject jit: Fix JIT_CODE_MOVE filename Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 068/112] drm/i915: Perform GGTT restore much earlier during resume Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 069/112] blk-wbt: fix performance regression in wbt scale_up/scale_down Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 070/112] selinux: fix context string corruption in convert_context() Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 071/112] CIFS: Gracefully handle QueryInfo errors during open Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 072/112] CIFS: Force revalidate inode when dentry is stale Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 073/112] CIFS: Force reval dentry if LOOKUP_REVAL flag is set Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 074/112] cifs: use cifsInodeInfo->open_file_lock while iterating to avoid a panic Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 075/112] kernel/sysctl.c: do not override max_threads provided by userspace Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 076/112] mm/z3fold.c: claim page in the beginning of free Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 077/112] mm/page_alloc.c: fix a crash in free_pages_prepare() Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 078/112] mm/vmpressure.c: fix a signedness bug in vmpressure_register_event() Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 079/112] IB/core: Fix wrong iterating on ports Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 080/112] firmware: google: increment VPD key_len properly Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 081/112] gpio: fix getting nonexclusive gpiods from DT Greg Kroah-Hartman
2019-10-16 21:51 ` Greg Kroah-Hartman [this message]
2019-10-16 21:51 ` [PATCH 5.3 083/112] btrfs: relocation: fix use-after-free on dead relocation roots Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 084/112] btrfs: allocate new inode in NOFS context Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 085/112] btrfs: fix balance convert to single on 32-bit host CPUs Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 086/112] Btrfs: fix memory leak due to concurrent append writes with fiemap Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 087/112] btrfs: fix incorrect updating of log root tree Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 088/112] btrfs: fix uninitialized ret in ref-verify Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 089/112] NFS: Fix O_DIRECT accounting of number of bytes read/written Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 090/112] MIPS: Disable Loongson MMI instructions for kernel build Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 091/112] MIPS: elf_hwcap: Export userspace ASEs Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 092/112] RDMA/vmw_pvrdma: Free SRQ only once Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 093/112] ACPI/PPTT: Add support for ACPI 6.3 thread flag Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 094/112] arm64: topology: Use PPTT to determine if PE is a thread Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 095/112] iio: light: fix vcnl4000 devicetree hooks Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 096/112] Fix the locking in dcache_readdir() and friends Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 097/112] drm/i915: Bump skl+ max plane width to 5k for linear/x-tiled Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 098/112] drm/i915: Whitelist COMMON_SLICE_CHICKEN2 Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 099/112] drm/i915: Mark contents as dirty on a write fault Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 100/112] drm/msm: Use the correct dma_sync calls harder Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 101/112] media: stkwebcam: fix runtime PM after driver unbind Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 102/112] arm64/sve: Fix wrong free for task->thread.sve_state Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 103/112] tracing/hwlat: Report total time spent in all NMIs during the sample Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 104/112] tracing/hwlat: Dont ignore outer-loop duration when calculating max_latency Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 105/112] ftrace: Get a reference counter for the trace_array on filter files Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 106/112] tracing: Get trace_array reference for available_tracers files Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 107/112] hwmon: Fix HWMON_P_MIN_ALARM mask Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 108/112] mtd: rawnand: au1550nd: Fix au_read_buf16() prototype Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 109/112] x86/asm: Fix MWAITX C-state hint value Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 110/112] io_uring: only flush workqueues on fileset removal Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 111/112] efi/tpm: Fix sanity check of unsigned tbl_size being less than zero Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 5.3 112/112] ASoC: sgtl5000: add ADC mute control Greg Kroah-Hartman
2019-10-16 22:00   ` Mark Brown
2019-10-16 22:10     ` Greg Kroah-Hartman
2019-10-16 22:35       ` Mark Brown
2019-10-16 23:23         ` Greg Kroah-Hartman
2019-10-17  9:20           ` Richard Leitner
     [not found]             ` <AM6PR05MB653568E379699EE907E146BDF96D0@AM6PR05MB6535.eurprd05.prod.outlook.com>
2019-10-17  9:49               ` Fw: " Oleksandr Suvorov
2019-10-17 11:11                 ` Mark Brown
2019-10-17 14:16                   ` Oleksandr Suvorov
2019-10-17 16:39                     ` Mark Brown
2019-10-18  9:55                       ` Oleksandr Suvorov
2019-10-17 11:46             ` Greg Kroah-Hartman
2019-10-17  4:42 ` [PATCH 5.3 000/112] 5.3.7-stable review kernelci.org bot
2019-10-17 15:13 ` shuah
2019-10-17 15:55   ` Greg Kroah-Hartman
2019-10-17 17:21 ` Naresh Kamboju
2019-10-17 20:35   ` Greg Kroah-Hartman
2019-10-17 18:04 ` Guenter Roeck
2019-10-17 18:21   ` Greg Kroah-Hartman
2019-10-17 18:30 ` Didik Setiawan
2019-10-17 20:35   ` Greg Kroah-Hartman
2019-10-18  8:01 ` Jon Hunter
2019-10-18 10:12   ` Greg Kroah-Hartman

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=20191016214904.700115170@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /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).