Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1025545imm; Wed, 6 Jun 2018 09:19:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKICn4TzKJZdlfXyq/NcLY6CjPhigiBHBgXv58zoNz+bjYoA9mOUWLZpdrW0v8i4BTlqfe9J X-Received: by 2002:a62:1411:: with SMTP id 17-v6mr3105118pfu.3.1528301957559; Wed, 06 Jun 2018 09:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528301957; cv=none; d=google.com; s=arc-20160816; b=ckQ0wE/IO2f7TMvyG/C7JMSQJwjVKb0znEXr9xUz7kyY3T57sq/KZGTWFotDP0Kn9b orlhk2xXY1sOQNbBgs57EAlpQlur1Q3WUE0JtWJfvBepKsjQPuRlqE84HX64N0tyqr02 DDafeQiZP+auHH0GcyTA/hX9qD8MZs52c4aPVVI7NsnSgXgedRGMKC2zc7yKUmH+uSuO vPW9vrJ3EbWj6/rxGKGLX/d5XVSZ1anGVt2eqEVQr4TS/VbnLKakodLV7GlOcQgCU9dy iuRXYH6lMT33CTSIOS5lKs9HF0/PeuQre0i8ZGHECViMqxP5KTSlLqWlWV78/hwOypCc ZfMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=BKZ4rxBxYrdxjIgnVb+y3vBvWpJ56UA7xnuo9rsXUdo=; b=z5PbMWZIVCr2w+PozaJ1FVScWNYY/MQ+Fp7j+VQncCkPa+SuSBUWx1q9LfbNQnxcL+ 0p3BavytoCsHTHpVir5uW2nTNRnqlqSYL/secc9AFtji2tqYQTUrhkVeeuTcWlHsW71X HTKkCN1IAC5S2iwKzQBImEtOMnE1NMIYtyD/LiesTaE2MLgnMnnctrF/7Gf9ACeQxCnU +josxIl2DRat33Fv5AOECzWO5B7kBYZRHWBfblya4YLG0ZcAlU7aejtYv9GgTVdu7dtv mkwLa8ddc/EdD9T0QtS8ygk0ad5R0kg8wmE8v3LyWWVRGohpSFK9PpP49Wcxn/2FGpfX UuLw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 199-v6si20093357pgd.74.2018.06.06.09.18.32; Wed, 06 Jun 2018 09:19:17 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932514AbeFFQQW (ORCPT + 99 others); Wed, 6 Jun 2018 12:16:22 -0400 Received: from hera.aquilenet.fr ([185.233.100.1]:56784 "EHLO hera.aquilenet.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932522AbeFFQQS (ORCPT ); Wed, 6 Jun 2018 12:16:18 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id EF76CD12; Wed, 6 Jun 2018 18:16:16 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1DoZdL1ODHnr; Wed, 6 Jun 2018 18:16:15 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (78-13-161.static.cyta.gr [78.87.13.161]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 222C8C79; Wed, 6 Jun 2018 18:16:15 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1fQYSK-0008EN-Mg; Wed, 06 Jun 2018 15:26:28 +0200 Date: Wed, 6 Jun 2018 15:26:28 +0200 From: Samuel Thibault To: "Speakup is a screen review system for Linux." Cc: devel@driverdev.osuosl.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: speakup: refactor synths array to use a list Message-ID: <20180606132628.fxykchbznrwzgwqt@var.youpi.perso.aquilenet.fr> Mail-Followup-To: Samuel Thibault , "Speakup is a screen review system for Linux." , devel@driverdev.osuosl.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org References: <20180604095212.GA18381@tanglefoot> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="7h5wgb64zoq25wmd" Content-Disposition: inline In-Reply-To: <20180604095212.GA18381@tanglefoot> Organization: I am not organized User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --7h5wgb64zoq25wmd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, Justin Skists, le lun. 04 juin 2018 10:52:12 +0100, a ecrit: > The synths[] array is a collection of synths acting like a list. > There is no need for synths to be an array, so refactor synths[] to use > standard kernel list_head API, instead, and modify the usages to suit. > As a side-effect, the maximum number of synths has also become redundant. This looks good to me, Reviewed-by: Samuel Thibault Did you test to e.g. insmod speakup_soft ; insmod speakup_dummy ; rmmod speakup_soft ; rmmod speakup_dummy to make sure it did work correctly? I'd also rather see it tested in the real wild before committing. Could somebody on the speakup mailing list test the patch? (which I have re-attached as a file for conveniency). Samuel --7h5wgb64zoq25wmd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch --- drivers/staging/speakup/spk_types.h | 2 ++ drivers/staging/speakup/synth.c | 40 ++++++++++------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/drivers/staging/speakup/spk_types.h b/drivers/staging/speakup/spk_types.h index 3e082dc3d45c..a2fc72c29894 100644 --- a/drivers/staging/speakup/spk_types.h +++ b/drivers/staging/speakup/spk_types.h @@ -160,6 +160,8 @@ struct spk_io_ops { }; struct spk_synth { + struct list_head node; + const char *name; const char *version; const char *long_name; diff --git a/drivers/staging/speakup/synth.c b/drivers/staging/speakup/synth.c index 7deeb7061018..25f259ee4ffc 100644 --- a/drivers/staging/speakup/synth.c +++ b/drivers/staging/speakup/synth.c @@ -18,8 +18,7 @@ #include "speakup.h" #include "serialio.h" -#define MAXSYNTHS 16 /* Max number of synths in array. */ -static struct spk_synth *synths[MAXSYNTHS + 1]; +static LIST_HEAD(synths); struct spk_synth *synth; char spk_pitch_buff[32] = ""; static int module_status; @@ -355,9 +354,8 @@ struct var_t synth_time_vars[] = { /* called by: speakup_init() */ int synth_init(char *synth_name) { - int i; int ret = 0; - struct spk_synth *synth = NULL; + struct spk_synth *tmp, *synth = NULL; if (!synth_name) return 0; @@ -371,9 +369,10 @@ int synth_init(char *synth_name) mutex_lock(&spk_mutex); /* First, check if we already have it loaded. */ - for (i = 0; i < MAXSYNTHS && synths[i]; i++) - if (strcmp(synths[i]->name, synth_name) == 0) - synth = synths[i]; + list_for_each_entry(tmp, &synths, node) { + if (strcmp(tmp->name, synth_name) == 0) + synth = tmp; + } /* If we got one, initialize it now. */ if (synth) @@ -448,29 +447,23 @@ void synth_release(void) /* called by: all_driver_init() */ int synth_add(struct spk_synth *in_synth) { - int i; int status = 0; + struct spk_synth *tmp; mutex_lock(&spk_mutex); - for (i = 0; i < MAXSYNTHS && synths[i]; i++) - /* synth_remove() is responsible for rotating the array down */ - if (in_synth == synths[i]) { + + list_for_each_entry(tmp, &synths, node) { + if (tmp == in_synth) { mutex_unlock(&spk_mutex); return 0; } - if (i == MAXSYNTHS) { - pr_warn("Error: attempting to add a synth past end of array\n"); - mutex_unlock(&spk_mutex); - return -1; } if (in_synth->startup) status = do_synth_init(in_synth); - if (!status) { - synths[i++] = in_synth; - synths[i] = NULL; - } + if (!status) + list_add_tail(&in_synth->node, &synths); mutex_unlock(&spk_mutex); return status; @@ -479,17 +472,10 @@ EXPORT_SYMBOL_GPL(synth_add); void synth_remove(struct spk_synth *in_synth) { - int i; - mutex_lock(&spk_mutex); if (synth == in_synth) synth_release(); - for (i = 0; synths[i]; i++) { - if (in_synth == synths[i]) - break; - } - for ( ; synths[i]; i++) /* compress table */ - synths[i] = synths[i + 1]; + list_del(&in_synth->node); module_status = 0; mutex_unlock(&spk_mutex); } -- 2.17.1 --7h5wgb64zoq25wmd--