Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751101AbdFTKHi (ORCPT ); Tue, 20 Jun 2017 06:07:38 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:35112 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846AbdFTKHh (ORCPT ); Tue, 20 Jun 2017 06:07:37 -0400 Date: Tue, 20 Jun 2017 11:07:32 +0100 From: Okash Khawaja To: Greg Kroah-Hartman , Samuel Thibault , linux-kernel@vger.kernel.org Cc: William Hubbs , Chris Brannon , Kirk Reiser , speakup@linux-speakup.org, devel@driverdev.osuosl.org Subject: [patch] staging: speakup: fix synth caching when synth init fails Message-ID: <20170620100732.GA14236@sanghar> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1160 Lines: 38 synths[] array caches currently loaded synths. synth_add checks synths[] before adding a new one. It however ignores the result of do_synth_init. So when do_synth_init fails, the failed synth is still cached. Since, as a result module loading fails too, synth_remove - which is responsible for removing the cached synth - is never called. Next time the failing synth is added again it succeeds because synth_add finds it cached inside synths[]. This patch fixes this by caching a synth only after do_synth_init succeeds. Signed-off-by: Okash Khawaja Reviewed-by: Samuel Thibault --- drivers/staging/speakup/synth.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/drivers/staging/speakup/synth.c +++ b/drivers/staging/speakup/synth.c @@ -445,10 +445,15 @@ int synth_add(struct spk_synth *in_synth mutex_unlock(&spk_mutex); return -1; } - synths[i++] = in_synth; - synths[i] = NULL; + if (in_synth->startup) status = do_synth_init(in_synth); + + if (!status) { + synths[i++] = in_synth; + synths[i] = NULL; + } + mutex_unlock(&spk_mutex); return status; }