From patchwork Wed Jun 13 05:52:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Raghavan X-Patchwork-Id: 9256 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4267E23E5A for ; Wed, 13 Jun 2012 05:52:56 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id C2125A18AA0 for ; Wed, 13 Jun 2012 05:52:53 +0000 (UTC) Received: by yenq6 with SMTP id q6so234864yen.11 for ; Tue, 12 Jun 2012 22:52:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:message-id :subject:from:to:cc:date:in-reply-to:references:content-type :x-mailer:mime-version:x-gm-message-state; bh=RF4dFtDeeCMBOQi3T1GbwybsCxVZtBMbVZ9wEgWPtlI=; b=Fa3gO4Jhz7irUPUl1meL4/LJqwU8F2+L7gdp9HHg9/aHZY0mKUZ8yoKy5RIeDfRDsR El3aVJrIw1uyz91ozpEY5y3kuvXr3hLHRPl41x4p/7RFh9SJCvkL8h3GgpYa2Z7sk5es znxfFZqKyPe6chpkTQ/UW4Pkz0+DZEwtNav7rQeRQDQvInWbffKe6/EYQBiKOrnEapow SI6Y1D3OQ7JTzaAWTboPl1dZOHqieOX0ANV6WiZtVp/4CF22zBMtWjXOm7Zod2V03thz 5cEM3PqgWjdaufgfNzv6ZqeK6XafCqVwongiOCmqBe3exhbMo5Z1mo79m6Cz0CHxdQ4M BxIQ== Received: by 10.50.57.167 with SMTP id j7mr9746379igq.53.1339566773183; Tue, 12 Jun 2012 22:52:53 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp4010ibb; Tue, 12 Jun 2012 22:52:52 -0700 (PDT) Received: by 10.216.26.201 with SMTP id c51mr5701269wea.108.1339566770498; Tue, 12 Jun 2012 22:52:50 -0700 (PDT) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk. [93.93.135.160]) by mx.google.com with ESMTPS id cj6si2811637wib.20.2012.06.12.22.52.49 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 12 Jun 2012 22:52:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of arun.raghavan@collabora.co.uk designates 93.93.135.160 as permitted sender) client-ip=93.93.135.160; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of arun.raghavan@collabora.co.uk designates 93.93.135.160 as permitted sender) smtp.mail=arun.raghavan@collabora.co.uk Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: arun) with ESMTPSA id CCF1C60013B Message-ID: <1339566767.5228.22.camel@localhost> Subject: Re: [pulseaudio-discuss] [RFC PATCH 1/4] Integrate UCM basic functions into alsa card module From: Arun Raghavan To: General PulseAudio Discussion Cc: broonie@opensource.wolfsonmicro.com, lrg@ti.com, patches@linaro.org Date: Wed, 13 Jun 2012 11:22:47 +0530 In-Reply-To: References: <1337335608-6901-1-git-send-email-feng.wei@linaro.org> <1337335608-6901-2-git-send-email-feng.wei@linaro.org> <1339156202.22591.23.camel@localhost> X-Mailer: Evolution 3.2.3 Mime-Version: 1.0 X-Gm-Message-State: ALoCoQk1bX1zqbi786sdkkT1wwRdDbOkrFr019QfNscNNW+kcqAE6Jt91gX7+l8pNb2JkxKdJ0kb Hi, On Mon, 2012-06-11 at 18:28 +0800, Feng Wei wrote: [snip] > >> +static int ucm_port_contain(const char *port_name, const char *dev_name) { > >> + int ret=0; > >> + char *r; > >> + const char *state=NULL; > >> + > >> + if (!port_name || !dev_name) > >> + return FALSE; > >> + > >> + while ((r = pa_split(port_name, "+", &state))) { > >> + if (!strcmp(r, dev_name)) { > >> + pa_xfree(r); > >> + ret = 1; > >> + break; > >> + } > >> + pa_xfree(r); > >> + } > >> + return ret; > >> +} > > > > Better to use strstr() here. Avoids some unnecessary allocation + > > deallocation. > Is it possible that we have sub string matching in error? I'm attaching a patch snippet of something that might be useful instead. Untested, but should work -- if it looks fine, I can commit this. One comment that I missed, I think -- I see that you've called structures pa_alsa_ucm_* and functions pa_ucm_*. Could you make them all pa_alsa_ucm_*? Thanks for all the efforts, Arun diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index dc9412f..e2e1ec7 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -947,6 +947,27 @@ char *pa_split(const char *c, const char *delimiter, const char**state) { return pa_xstrndup(current, l); } +/* Split the specified string wherever one of the strings in delimiter + * occurs. Each time it is called returns a pointer to the substring within the + * string and the length in n. The variable state points to, should be + * initialized to NULL before the first call. */ +const char *pa_split_in_place(const char *c, const char *delimiter, int *n, const char**state) { + const char *current = *state ? *state : c; + size_t l; + + if (!*current) + return NULL; + + l = strcspn(current, delimiter); + *state = current+l; + + if (**state) + (*state)++; + + *n = l; + return current; +} + /* Split a string into words. Otherwise similar to pa_split(). */ char *pa_split_spaces(const char *c, const char **state) { const char *current = *state ? *state : c; diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 4a1c096..a3c2247 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -100,6 +100,7 @@ static inline const char *pa_strna(const char *x) { } char *pa_split(const char *c, const char*delimiters, const char **state); +const char *pa_split_in_place(const char *c, const char*delimiters, int *n, const char **state); char *pa_split_spaces(const char *c, const char **state); char *pa_strip_nl(char *s);