Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4630982imm; Mon, 11 Jun 2018 16:10:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLYTfEwZwcDIvjFdOQyq6izM2Nw4LAPhM4x9dSB2SR8xQfGM5h46UzYo2lxC3Ps608Qp1Ix X-Received: by 2002:a17:902:a416:: with SMTP id p22-v6mr1202325plq.228.1528758651342; Mon, 11 Jun 2018 16:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528758651; cv=none; d=google.com; s=arc-20160816; b=l9PAbVLTB0Vjx0nZ2YtLw3wEhygv3/E1sjm03Ga9eBVZ4+giFnfeSUZ13x39ZxC5P3 u1FslsdBcuILjbWKn3f8/OVZLjCqDrJ3TBxBUOh9XqBd3045MR0H4zAIySllDQr972vb 1uzzy5pI3KLmVMbv+j/wQHtV1T79qhXVAKgnNDMNQE0odgQ51x7ZHhLOEfDEtpZiQinZ RtoBoJXQsBR4jNy84WhazF5TEjXim5+pu0TFeJp9xOtCVLaA9ygRHJiSjoCIZ/H1h7tA DQXReSb5uib0pyUnzxV6wJQnqJJZf89iFbSdiwgTDNLX9DRGEbY3AUZswSLLwsxz5RIt gAPQ== 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:to:from:date:arc-authentication-results; bh=0adhoG/EGcjQyU6KXO5tqW9VBQ/cxcfGytqSln5GX0E=; b=J432VRPFj1V+vGw3YCgjU3EF+MH5XWzFdMT/r9V6MLT0r6kx/jt2Wm1GrWliRtxqLv XC4msfs8u4aAK6dpB73MQjubN2qXfgAC3AWA8bKdFiJRaDmzUg1LV0ZXVNuaTQOmICmX mKPjM87DTJsGvkLXc+rW4l5gtF8CZK24xVnftZ8pVDjx8lkWpMKWUiafBLAMGtdv8FGF g8LrDfR2MUr2f0NSz2RdpvuFynYpMCi9OztoYly1uopOxVyVJObIhy2JALM2vWCCxuyi GyJ224SsJApzrlWzkbjXYsAlPjB81i7ZzKY+LrjqoETkisFhnkm8waFmvBY9sztRyw1/ Jwbg== 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 c7-v6si30449536pfg.77.2018.06.11.16.10.37; Mon, 11 Jun 2018 16:10:51 -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 S1754210AbeFKW5I (ORCPT + 99 others); Mon, 11 Jun 2018 18:57:08 -0400 Received: from hera.aquilenet.fr ([185.233.100.1]:40850 "EHLO hera.aquilenet.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbeFKW5H (ORCPT ); Mon, 11 Jun 2018 18:57:07 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id BDA8AE4D; Tue, 12 Jun 2018 00:57:04 +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 HG29ISmkqy8T; Tue, 12 Jun 2018 00:57:04 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (static-176-158-111-12.ftth.abo.bbox.fr [176.158.111.12]) by hera.aquilenet.fr (Postfix) with ESMTPSA id E126EE4C; Tue, 12 Jun 2018 00:57:03 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1fSVkF-0004Lb-5g; Tue, 12 Jun 2018 00:57:03 +0200 Date: Tue, 12 Jun 2018 00:57:03 +0200 From: Samuel Thibault To: "Speakup is a screen review system for Linux." , 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: <20180611225703.csi47cdafhy6rxcf@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> <20180606132628.fxykchbznrwzgwqt@var.youpi.perso.aquilenet.fr> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="55pr6ffpo36jsalk" Content-Disposition: inline In-Reply-To: <20180606132628.fxykchbznrwzgwqt@var.youpi.perso.aquilenet.fr> 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 --55pr6ffpo36jsalk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, Samuel Thibault, le mer. 06 juin 2018 15:26:28 +0200, a ecrit: > 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). Anybody up for testing please? If people want to see speakup get mainlined instead of staging, please help. Samuel --55pr6ffpo36jsalk 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 --55pr6ffpo36jsalk--