mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Takashi Iwai <tiwai@suse.de>, Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 3.13.y-ckt 66/80] ALSA: ak411x: Fix stall in work callback
Date: Thu, 19 Mar 2015 15:35:54 -0700	[thread overview]
Message-ID: <1426804568-2907-67-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1426804568-2907-1-git-send-email-kamal@canonical.com>

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

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

From: Takashi Iwai <tiwai@suse.de>

commit 4161b4505f1690358ac0a9ee59845a7887336b21 upstream.

When ak4114 work calls its callback and the callback invokes
ak4114_reinit(), it stalls due to flush_delayed_work().  For avoiding
this, control the reentrance by introducing a refcount.  Also
flush_delayed_work() is replaced with cancel_delayed_work_sync().

The exactly same bug is present in ak4113.c and fixed as well.

Reported-by: Pavel Hofman <pavel.hofman@ivitera.com>
Acked-by: Jaroslav Kysela <perex@perex.cz>
Tested-by: Pavel Hofman <pavel.hofman@ivitera.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 include/sound/ak4113.h   |  2 +-
 include/sound/ak4114.h   |  2 +-
 sound/i2c/other/ak4113.c | 17 ++++++++---------
 sound/i2c/other/ak4114.c | 18 ++++++++----------
 4 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/include/sound/ak4113.h b/include/sound/ak4113.h
index 2609048..3a34f6e 100644
--- a/include/sound/ak4113.h
+++ b/include/sound/ak4113.h
@@ -286,7 +286,7 @@ struct ak4113 {
 	ak4113_write_t *write;
 	ak4113_read_t *read;
 	void *private_data;
-	unsigned int init:1;
+	atomic_t wq_processing;
 	spinlock_t lock;
 	unsigned char regmap[AK4113_WRITABLE_REGS];
 	struct snd_kcontrol *kctls[AK4113_CONTROLS];
diff --git a/include/sound/ak4114.h b/include/sound/ak4114.h
index 52f02a6..069299a 100644
--- a/include/sound/ak4114.h
+++ b/include/sound/ak4114.h
@@ -168,7 +168,7 @@ struct ak4114 {
 	ak4114_write_t * write;
 	ak4114_read_t * read;
 	void * private_data;
-	unsigned int init: 1;
+	atomic_t wq_processing;
 	spinlock_t lock;
 	unsigned char regmap[6];
 	unsigned char txcsb[5];
diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c
index e04e750..7a9149b 100644
--- a/sound/i2c/other/ak4113.c
+++ b/sound/i2c/other/ak4113.c
@@ -56,8 +56,7 @@ static inline unsigned char reg_read(struct ak4113 *ak4113, unsigned char reg)
 
 static void snd_ak4113_free(struct ak4113 *chip)
 {
-	chip->init = 1;	/* don't schedule new work */
-	mb();
+	atomic_inc(&chip->wq_processing);	/* don't schedule new work */
 	cancel_delayed_work_sync(&chip->work);
 	kfree(chip);
 }
@@ -89,6 +88,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
 	chip->write = write;
 	chip->private_data = private_data;
 	INIT_DELAYED_WORK(&chip->work, ak4113_stats);
+	atomic_set(&chip->wq_processing, 0);
 
 	for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++)
 		chip->regmap[reg] = pgm[reg];
@@ -139,13 +139,11 @@ static void ak4113_init_regs(struct ak4113 *chip)
 
 void snd_ak4113_reinit(struct ak4113 *chip)
 {
-	chip->init = 1;
-	mb();
-	flush_delayed_work(&chip->work);
+	if (atomic_inc_return(&chip->wq_processing) == 1)
+		cancel_delayed_work_sync(&chip->work);
 	ak4113_init_regs(chip);
 	/* bring up statistics / event queing */
-	chip->init = 0;
-	if (chip->kctls[0])
+	if (atomic_dec_and_test(&chip->wq_processing))
 		schedule_delayed_work(&chip->work, HZ / 10);
 }
 EXPORT_SYMBOL_GPL(snd_ak4113_reinit);
@@ -632,8 +630,9 @@ static void ak4113_stats(struct work_struct *work)
 {
 	struct ak4113 *chip = container_of(work, struct ak4113, work.work);
 
-	if (!chip->init)
+	if (atomic_inc_return(&chip->wq_processing) == 1)
 		snd_ak4113_check_rate_and_errors(chip, chip->check_flags);
 
-	schedule_delayed_work(&chip->work, HZ / 10);
+	if (atomic_dec_and_test(&chip->wq_processing))
+		schedule_delayed_work(&chip->work, HZ / 10);
 }
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 15ae025..bf515db 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -66,8 +66,7 @@ static void reg_dump(struct ak4114 *ak4114)
 
 static void snd_ak4114_free(struct ak4114 *chip)
 {
-	chip->init = 1;	/* don't schedule new work */
-	mb();
+	atomic_inc(&chip->wq_processing);	/* don't schedule new work */
 	cancel_delayed_work_sync(&chip->work);
 	kfree(chip);
 }
@@ -100,6 +99,7 @@ int snd_ak4114_create(struct snd_card *card,
 	chip->write = write;
 	chip->private_data = private_data;
 	INIT_DELAYED_WORK(&chip->work, ak4114_stats);
+	atomic_set(&chip->wq_processing, 0);
 
 	for (reg = 0; reg < 6; reg++)
 		chip->regmap[reg] = pgm[reg];
@@ -152,13 +152,11 @@ static void ak4114_init_regs(struct ak4114 *chip)
 
 void snd_ak4114_reinit(struct ak4114 *chip)
 {
-	chip->init = 1;
-	mb();
-	flush_delayed_work(&chip->work);
+	if (atomic_inc_return(&chip->wq_processing) == 1)
+		cancel_delayed_work_sync(&chip->work);
 	ak4114_init_regs(chip);
 	/* bring up statistics / event queing */
-	chip->init = 0;
-	if (chip->kctls[0])
+	if (atomic_dec_and_test(&chip->wq_processing))
 		schedule_delayed_work(&chip->work, HZ / 10);
 }
 
@@ -612,10 +610,10 @@ static void ak4114_stats(struct work_struct *work)
 {
 	struct ak4114 *chip = container_of(work, struct ak4114, work.work);
 
-	if (!chip->init)
+	if (atomic_inc_return(&chip->wq_processing) == 1)
 		snd_ak4114_check_rate_and_errors(chip, chip->check_flags);
-
-	schedule_delayed_work(&chip->work, HZ / 10);
+	if (atomic_dec_and_test(&chip->wq_processing))
+		schedule_delayed_work(&chip->work, HZ / 10);
 }
 
 EXPORT_SYMBOL(snd_ak4114_create);
-- 
1.9.1


  parent reply	other threads:[~2015-03-19 22:44 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19 22:34 [3.13.y-ckt stable] Linux 3.13.11-ckt17 stable review Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 01/80] splice: Apply generic position and size checks to each write Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 02/80] clocksource: arch_timer: Only use the virtual counter (CNTVCT) on arm64 Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 03/80] openvswitch: Silence RCU lockdep checks from flow lookup Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 04/80] openvswitch: Use exact lookup for flow_get and flow_del Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 05/80] Bluetooth: Enable Atheros 0cf3:311e for firmware upload Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 06/80] Bluetooth: Add firmware update for Atheros 0cf3:311f Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 07/80] Bluetooth: btusb: Add IMC Networks (Broadcom based) Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 08/80] Bluetooth: sort the list of IDs in the source code Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 09/80] Bluetooth: append new supported device to the list [0b05:17d0] Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 10/80] Bluetooth: Add support for Intel bootloader devices Kamal Mostafa
2015-03-19 22:34 ` [PATCH 3.13.y-ckt 11/80] Bluetooth: Ignore isochronous endpoints for Intel USB bootloader Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 12/80] Bluetooth: Add support for Acer [13D3:3432] Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 13/80] Bluetooth: Add support for Broadcom device of Asus Z97-DELUXE motherboard Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 14/80] Add a new PID/VID 0227/0930 for AR3012 Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 15/80] Bluetooth: Add support for Acer [0489:e078] Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 16/80] Bluetooth: Add USB device 04ca:3010 as Atheros AR3012 Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 17/80] x86: mm: move mmap_sem unlock from mm_fault_error() to caller Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 18/80] vm: add VM_FAULT_SIGSEGV handling support Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 19/80] vm: make stack guard page errors return VM_FAULT_SIGSEGV rather than SIGBUS Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 20/80] net: sctp: fix slab corruption from use after free on INIT collisions Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 21/80] ipv4: try to cache dst_entries which would cause a redirect Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 22/80] x86, mm/ASLR: Fix stack randomization on 64-bit systems Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 23/80] net: llc: use correct size for sysctl timeout entries Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 24/80] net: rds: use correct size for max unacked packets and bytes Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 25/80] spi/pxa2xx: Clear cur_chip pointer before starting next message Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 26/80] spi: dw: Fix detecting FIFO depth Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 27/80] spi: dw-mid: fix FIFO size Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 28/80] ASoC: wm8960: Fix capture sample rate from 11250 to 11025 Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 29/80] regulator: core: fix race condition in regulator_put() Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 30/80] ASoC: omap-mcbsp: Correct CBM_CFS dai format configuration Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 31/80] powerpc/xmon: Fix another endiannes issue in RTAS call from xmon Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 32/80] can: c_can: end pending transmission on network stop (ifdown) Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 33/80] nfs: fix dio deadlock when O_DIRECT flag is flipped Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 34/80] NFSv4.1: Fix an Oops in nfs41_walk_client_list Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 35/80] Input: i8042 - add noloop quirk for Medion Akoya E7225 (MD98857) Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 36/80] mac80211: properly set CCK flag in radiotap Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 37/80] nl80211: fix per-station group key get/del and memory leak Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 38/80] i2c: s3c2410: fix ABBA deadlock by keeping clock prepared Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 39/80] usb-storage/SCSI: blacklist FUA on JMicron 152d:2566 USB-SATA controller Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 40/80] drm/i915: Only fence tiled region of object Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 41/80] drm/i915: Fix and clean BDW PCH identification Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 42/80] drm/i915: BDW Fix Halo PCI IDs marked as ULT Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 43/80] ALSA: seq-dummy: remove deadlock-causing events on close Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 44/80] drivers/rtc/rtc-s5m.c: terminate s5m_rtc_id array with empty element Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 45/80] drivers: net: cpsw: discard dual emac default vlan configuration Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 46/80] can: kvaser_usb: Do not sleep in atomic context Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 47/80] can: kvaser_usb: Send correct context to URB completion Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 48/80] can: kvaser_usb: Retry the first bulk transfer on -ETIMEDOUT Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 49/80] can: kvaser_usb: Fix state handling upon BUS_ERROR events Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 50/80] quota: Switch ->get_dqblk() and ->set_dqblk() to use bytes as space units Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 51/80] rbd: fix rbd_dev_parent_get() when parent_overlap == 0 Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 52/80] rbd: drop parent_ref in rbd_dev_unprobe() unconditionally Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 53/80] dm cache: fix missing ERR_PTR returns and handling Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 54/80] dm thin: don't allow messages to be sent to a pool target in READ_ONLY or FAIL mode Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 55/80] net: cls_bpf: fix size mismatch on filter preparation Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 56/80] net: cls_bpf: fix auto generation of per list handles Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 57/80] ipv6: replacing a rt6_info needs to purge possible propagated rt6_infos too Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 58/80] perf: Tighten (and fix) the grouping condition Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 59/80] arc: mm: Fix build failure Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 60/80] MIPS: IRQ: Fix disable_irq on CPU IRQs Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 61/80] Complete oplock break jobs before closing file handle Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 62/80] smpboot: Add missing get_online_cpus() in smpboot_register_percpu_thread() Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 63/80] ASoC: atmel_ssc_dai: fix start event for I2S mode Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 64/80] spi: fsl-dspi: Fix memory leak Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 65/80] spi: spi-fsl-dspi: Remove usage of devm_kzalloc Kamal Mostafa
2015-03-19 22:35 ` Kamal Mostafa [this message]
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 67/80] lib/checksum.c: fix carry in csum_tcpudp_nofold Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 68/80] MIPS: Fix kernel lockup or crash after CPU offline/online Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 69/80] gpio: sysfs: fix memory leak in gpiod_export_link Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 70/80] gpio: sysfs: fix memory leak in gpiod_sysfs_set_active_low Kamal Mostafa
2015-03-19 22:35 ` [PATCH 3.13.y-ckt 71/80] MIPS: Fix C0_Pagegrain[IEC] support Kamal Mostafa
2015-03-19 23:10   ` David Daney
2015-03-20 17:02     ` Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 72/80] PCI: Add NEC variants to Stratus ftServer PCIe DMI check Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 73/80] ASoC: sgtl5000: add delay before first I2C access Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 74/80] PCI: Handle read-only BARs on AMD CS553x devices Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 75/80] mm: pagewalk: call pte_hole() for VM_PFNMAP during walk_page_range Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 76/80] nilfs2: fix deadlock of segment constructor over I_SYNC flag Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 77/80] tcp: ipv4: initialize unicast_sock sk_pacing_rate Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 78/80] caif: remove wrong dev_net_set() call Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 79/80] qlge: Fix qlge_update_hw_vlan_features to handle if interface is down Kamal Mostafa
2015-03-19 22:36 ` [PATCH 3.13.y-ckt 80/80] ip6_gre: fix endianness errors in ip6gre_err Kamal Mostafa

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=1426804568-2907-67-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.de \
    /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

all inboxes | Powered by JetHome®