From patchwork Thu Jul 26 10:28:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 10254 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 CF8E323E56 for ; Thu, 26 Jul 2012 10:29:25 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9FE65A18866 for ; Thu, 26 Jul 2012 10:29:25 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id f1so1772698ggn.11 for ; Thu, 26 Jul 2012 03:29:25 -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:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=vrE+dlSX5E9JWGHKViZLKqRLbPm97cYzt49jreKV0Qc=; b=kEzhXW6GB1ZcPMnRqKIU1WqFshixsoi26x/Y3S9OVhLwN8bN3wEWtesk5daK2ovtkx s3rd1L6zJuhR8IWbUjq/80/UqorOvCxeGdw74wfEGI4rdmUwI24bXSeXQvr9onnoZku+ EpcBFBLa9Ua0ZX+4WnuiT81mbzKaf9h6DiHpcwXmK21r2X31KOJ8oSAZPOhWpy4DA+Q1 j8NTA7353FX4RBVYxkrtoVCPSGyGlyx4CTryKRRW5+EIELEsqOaFAU6ui+WTtiRKzKWE 8yKIdAQwsreikNGhDnWpNpZ18KBoEus6NEhOlRoI79mMNS7EhsYl4NtaPN0zbTUe5wdG k3uA== Received: by 10.50.149.170 with SMTP id ub10mr1181846igb.38.1343298565256; Thu, 26 Jul 2012 03:29:25 -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.43.93.3 with SMTP id bs3csp133363icc; Thu, 26 Jul 2012 03:29:24 -0700 (PDT) Received: by 10.180.105.130 with SMTP id gm2mr12326406wib.6.1343298563921; Thu, 26 Jul 2012 03:29:23 -0700 (PDT) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx.google.com with ESMTPS id b4si9830060wiz.1.2012.07.26.03.29.23 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Jul 2012 03:29:23 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f178.google.com with SMTP id hr14so1342799wib.13 for ; Thu, 26 Jul 2012 03:29:23 -0700 (PDT) Received: by 10.180.100.133 with SMTP id ey5mr12330391wib.4.1343298563452; Thu, 26 Jul 2012 03:29:23 -0700 (PDT) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id fb20sm11559455wid.1.2012.07.26.03.29.21 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Jul 2012 03:29:22 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: STEricsson_nomadik_linux@list.st.com, linus.walleij@stericsson.com, arnd@arndb.de, broonie@opensource.wolfsonmicro.com, sameo@linux.intel.com, olalilja@yahoo.se, ola.o.lilja@stericsson.com, alsa-devel@alsa-project.org, lrg@ti.com, Lee Jones Subject: [PATCH 07/21] ASoC: io: Prevent use of regmap if request fails Date: Thu, 26 Jul 2012 11:28:40 +0100 Message-Id: <1343298534-13611-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1343298534-13611-1-git-send-email-lee.jones@linaro.org> References: <1343298534-13611-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQkUiqJkLSpXwKaS2KcyNTUZ21EH2Sj5V8uaOuDMmwYtAgCLGTdv8sT9rRjloJ79zdUJO4Vt If a sound codec fails to request a regmap, the 'using_regmap' is set as true regardless, despite there being no regmap to use. As a repercussion, when a latter read function checks to see if we are using regmaps, it assumes we are and attempts to. Only the kernel oopes, because regmap_* tries to extract information from a NULL pointer. Signed-off-by: Lee Jones --- sound/soc/soc-io.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c index 29183ef..601cb7f 100644 --- a/sound/soc/soc-io.c +++ b/sound/soc/soc-io.c @@ -52,10 +52,13 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg) if (codec->cache_only) return -1; - ret = regmap_read(codec->control_data, reg, &val); - if (ret == 0) - return val; - else + if (codec->using_regmap) { + ret = regmap_read(codec->control_data, reg, &val); + if (ret == 0) + return val; + else + return -1; + } else return -1; } @@ -141,11 +144,12 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, case SND_SOC_REGMAP: /* Device has made its own regmap arrangements */ - codec->using_regmap = true; if (!codec->control_data) codec->control_data = dev_get_regmap(codec->dev, NULL); if (codec->control_data) { + codec->using_regmap = true; + ret = regmap_get_val_bytes(codec->control_data); /* Errors are legitimate for non-integer byte * multiples */