Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2649673imu; Tue, 6 Nov 2018 19:26:06 -0800 (PST) X-Google-Smtp-Source: AJdET5cTHzTatrwTEfzscNS1YNOfeWW0qSequAlmEjYRMJE5glZSvQmkFPvzh3VET8rpPfbl2TTZ X-Received: by 2002:a63:981:: with SMTP id 123mr205934pgj.444.1541561166800; Tue, 06 Nov 2018 19:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541561166; cv=none; d=google.com; s=arc-20160816; b=rTr+BlsdGb+61nIQLdjKs0aKoqgrVQfT9VAdhWUW+mGS0puN06yDsYj00EvpKGgJ0X 5SE2v8nmuylFGLuh3wK/VVwR6fUA3Pu+MS+oc3hLRRpv8P5T9BFQomVNOkSZHH594UPw 0VVJyhyM3mTCkiq4oZtOSVOth5GHnz4YW8GBxWiZgHujNajloc72SL/IM6gvpLlb6+Rn rHxGucnGk1A0r0OWT2KtnsQBitsBV8Hqj8hqu3u3K7zuu9AQVAAajLVY6CkXHJCiooKm x8SXCvyuGA8bVgopocph8sdP0st3zzKueeXcx7eYRBMADUHkL0cl1lz21zLB1lHn7CE1 Lm6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=kCgTO/s0665b6qaKTlfUQY/pOagUo2u8AfR5Wyh2tWo=; b=wdWI3JbzNt28pqJtZHUZ35VzxJdEuEcxdmnIHMNF9B7iA/zRITULbIQ8eIT2RqbIlD rQZblkzW6zJDryI6tfNa1NYfX2S78KQ4D9aRYa+rjkrMP/cyxRPd75My21pe1t7mtsm+ YurWN8rEZEvcX+zLte22945rLxhIIXMCoGYO5JQrTiGmkrCs63bzDT2NuHrzw00FzXPV paAak9mIIcsHZXPQFrziZA+m8iTXVtZFbMKw4/qIRHXaDOb6rBHLZQykzIZgnvH8vaji IJCETw94ZX5FNAXBEJg61ll+6Rwz/reXr+br2Gru5HyjcsSW71Sebfrb/UiXbgemROPn KV6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EogAe5XH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3-v6si37554522pld.424.2018.11.06.19.25.51; Tue, 06 Nov 2018 19:26:06 -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; dkim=pass header.i=@linaro.org header.s=google header.b=EogAe5XH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730984AbeKGMwX (ORCPT + 99 others); Wed, 7 Nov 2018 07:52:23 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:41838 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727315AbeKGMwX (ORCPT ); Wed, 7 Nov 2018 07:52:23 -0500 Received: by mail-lf1-f65.google.com with SMTP id c16so10443829lfj.8 for ; Tue, 06 Nov 2018 19:23:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=kCgTO/s0665b6qaKTlfUQY/pOagUo2u8AfR5Wyh2tWo=; b=EogAe5XHSWI9SeDnE80BUFFtvwR1hdAcO2b9IoTbVBPg689Cm8meT4KwYmehH5aI97 PHT41hJwuAbE85c5G17FsYn/TnlA0MukJyPfSF3d3y+UZpPihmsU+tix3VCmtl4rF9yI zvyzEBsJEWvhxqO9s5uCbFdfHHznI47T5ZosA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=kCgTO/s0665b6qaKTlfUQY/pOagUo2u8AfR5Wyh2tWo=; b=h9WtfZY2D0nbeCSBLT+aEYN59+ndxpavdJoC0R79ieuN65F+ucEs/Q98569MEBVf/i 9jgop809IddWj8S2AQFW+U9WLpICyJzVHwXVtjiy0EkBq+edgHLvYdeILUl3VPt3SZYA 5f0N/awsypPnGWRszbtehbJ6r3BE0ZS6TB10QdQKONUAnxSQIYoTjQAVN1fJpYGbXKkV tM+sqGSbUQ+82kgssX3dVuxEqWBWgwU9mTMESDXfm477Pr3SjAi0l/cqUO1KI0a9eWJg DJQv7yZ8CSW1E6AfA9aIyXCPdXO+AFoUZ++tWCA756wDKwdzDgPXDe/VGUg38+tAF2Ml e6rA== X-Gm-Message-State: AGRZ1gLkdVdE/MCrWmUoUKb5paUI7GMCDL8dRV4YS7A7F9KotVstO7AX +EhDIlZ3AENbGjMIeM6YKO+HU83yRVK9fgxJtDWibw== X-Received: by 2002:a19:54d7:: with SMTP id b84mr70390lfl.131.1541561032602; Tue, 06 Nov 2018 19:23:52 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a2e:95ca:0:0:0:0:0 with HTTP; Tue, 6 Nov 2018 19:23:52 -0800 (PST) In-Reply-To: References: From: Baolin Wang Date: Wed, 7 Nov 2018 11:23:52 +0800 Message-ID: Subject: Re: [PATCH v14 1/2] leds: core: Introduce LED pattern trigger To: Geert Uytterhoeven Cc: Jacek Anaszewski , Pavel Machek , rteysseyre@gmail.com, =?UTF-8?Q?Bj=C3=B6rn_Andersson?= , Mark Brown , Linux LED Subsystem , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert, On 6 November 2018 at 23:57, Geert Uytterhoeven wrote: > Hi Baolin, > > On Tue, Oct 2, 2018 at 6:39 PM Baolin Wang wrote: >> This patch adds one new led trigger that LED device can configure >> the software or hardware pattern and trigger it. >> >> Consumers can write 'pattern' file to enable the software pattern >> which alters the brightness for the specified duration with one >> software timer. >> >> Moreover consumers can write 'hw_pattern' file to enable the hardware >> pattern for some LED controllers which can autonomously control >> brightness over time, according to some preprogrammed hardware >> patterns. >> >> Signed-off-by: Raphael Teysseyre >> Signed-off-by: Baolin Wang > >> --- /dev/null >> +++ b/drivers/leds/trigger/ledtrig-pattern.c >> @@ -0,0 +1,431 @@ > >> +static void pattern_trig_timer_function(struct timer_list *t) >> +{ >> + struct pattern_trig_data *data = from_timer(data, t, timer); >> + >> + mutex_lock(&data->lock); > > Timer functions run in interrupt context, hence if CONFIG_DEBUG_ATOMIC_SLEEP=y: > > BUG: sleeping function called from invalid context at kernel/locking/mutex.c:254 > in_atomic(): 1, irqs_disabled(): 0, pid: 0, name: swapper/1 > CPU: 1 PID: 0 Comm: swapper/1 Not tainted > 4.20.0-rc1-koelsch-00841-ga338c8181013c1a9 #171 > Hardware name: Generic R-Car Gen2 (Flattened Device Tree) > [] (unwind_backtrace) from [] (show_stack+0x10/0x14) > [] (show_stack) from [] (dump_stack+0x7c/0x9c) > [] (dump_stack) from [] (___might_sleep+0xf4/0x158) > [] (___might_sleep) from [] (mutex_lock+0x18/0x60) > [] (mutex_lock) from [] > (pattern_trig_timer_function+0x1c/0x11c) > [] (pattern_trig_timer_function) from [] > (call_timer_fn+0x1c/0x90) > [] (call_timer_fn) from [] (expire_timers+0x94/0xa4) > [] (expire_timers) from [] (run_timer_softirq+0x108/0x15c) > [] (run_timer_softirq) from [] (__do_softirq+0x1d4/0x258) > [] (__do_softirq) from [] (irq_exit+0x64/0xc4) > [] (irq_exit) from [] (__handle_domain_irq+0x80/0xb4) > [] (__handle_domain_irq) from [] (gic_handle_irq+0x58/0x90) > [] (gic_handle_irq) from [] (__irq_svc+0x58/0x74) > Exception stack(0xeb483f60 to 0xeb483fa8) > 3f60: 00000000 00000000 eb9afaa0 c0217e80 00000000 ffffe000 00000000 c0e06408 > 3f80: 00000002 c0e0647c c0c6a5f0 00000000 c0e04900 eb483fb0 c0207ea8 c0207e98 > 3fa0: 60020013 ffffffff > [] (__irq_svc) from [] (arch_cpu_idle+0x1c/0x38) > [] (arch_cpu_idle) from [] (do_idle+0x138/0x268) > [] (do_idle) from [] (cpu_startup_entry+0x18/0x1c) > [] (cpu_startup_entry) from [<402022ec>] (0x402022ec) > > Either this should use a spinlock instead of a mutex, or the timer > function should kick a workqueue to do the real work. > Ah, sorry I missed this. Good catch. After more thinking, the easy fix is that I think we can remove the mutex lock in pattern_trig_timer_function(). Since the mutex lock is used to protect the pattern trigger data, but before changing new pattern trigger data (pattern values or repeat value) by users, we always cancel the timer firstly to clear previous patterns' performance. That means there is no race in pattern_trig_timer_function(), so we can drop the mutex lock in pattern_trig_timer_function() to avoid this issue. I will send one patch to fix this issue. Thanks. -- Baolin Wang Best Regards