Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3398527imm; Mon, 4 Jun 2018 02:59:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJrDveHKY86S2XzY9DffEhKfAio0BLq9DKKxMMHI2uF0TLwkBBMzKGXCuoX0f1fJbq9Tj/1 X-Received: by 2002:a62:ba13:: with SMTP id k19-v6mr6125528pff.245.1528106361016; Mon, 04 Jun 2018 02:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528106360; cv=none; d=google.com; s=arc-20160816; b=UzKz29H5OMZWZvpTZ7+pSHa1UagepXKtoHeKGyZ4x0d3DjAHwLJEk7go5eiY14y0L/ eLyBQGw7lOenLEftoUklLhLTGal5tp60lF8BEN91WW4D1Roq+eyqDd0Qf9SyY/lJwUdD M/NaFJt+dQ8Temxjfm13aG4wok89Z0Y4dybdjiARxIckRTX4JKmMF324hzU7pz7zkAbM TcYQEir8iOSm5e4JQbYA02+yBYIDPh2EBAl/vk/0W2XnqTwe7PS0noKsyNMS2+hEL5Zz EnA/0u88A/9bG5ls35DtWOCWQPCg035mdFMCULIXG6snEx7bigP5wCaFkoj0o4Crnn1B 9Khw== 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=qAJuQqbpj3ej9tXxYJ62A3R6ZLHvLjS/gr8MfpO5ufk=; b=FnzF4VcvqB+szMswpZw4kFfcdBmvqAT1Bkeqg2vbWHvm4Ert1HQ67S33LWhDGJt0hY SPY+99XnjJd9nariS2A6bPp91BrZbeyLwK2wRxjVyAvZ9YWIrUUsbE4z0gmY3P1Qf+TS 5r+rMoj/SH6VQstClAXf1L1X2F+2S0tf8cxhGK7S2tY5o192fpyCZKbmBOYh/f97t4+k 5KTdgDLkz6+DDX3Q0YCb26XRgApymhhNQG53PnfbKv66RM4+LcFjc/AQN+LfINt3U01n T2OASWKqbNIEcI7LWMIDtxVJMl8s7kp0oZFc3eZAkWehyc8FJ0wfBoUTZAXw+A36aGEX Q1Ug== 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 100-v6si11900222plc.205.2018.06.04.02.59.06; Mon, 04 Jun 2018 02:59:20 -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 S1752196AbeFDJ5f (ORCPT + 99 others); Mon, 4 Jun 2018 05:57:35 -0400 Received: from hera.aquilenet.fr ([185.233.100.1]:36562 "EHLO hera.aquilenet.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751769AbeFDJ5d (ORCPT ); Mon, 4 Jun 2018 05:57:33 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1BFD0A30; Mon, 4 Jun 2018 11:57:32 +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 lYKiOyedIh5U; Mon, 4 Jun 2018 11:57:31 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (dhcp-13-150.lip.ens-lyon.fr [140.77.13.150]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 13304742; Mon, 4 Jun 2018 11:57:31 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1fPmF0-0005pp-N8; Mon, 04 Jun 2018 11:57:30 +0200 Date: Mon, 4 Jun 2018 11:57:30 +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: <20180604095730.l2vuzbapxeapr3ni@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: text/plain; charset=us-ascii 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 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. > > Signed-off-by: Justin Skists This needs a review, but the principle looks sound to me :) Thanks, Samuel > --- > 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 > > _______________________________________________ > Speakup mailing list > Speakup@linux-speakup.org > http://linux-speakup.org/cgi-bin/mailman/listinfo/speakup -- Samuel un driver qui fait quoi, alors ? ben pour les bips pour passer les oops en morse -+- #ens-mim - vive les rapports de bug -+-