From patchwork Thu Aug 28 13:14:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 36198 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 490112054F for ; Thu, 28 Aug 2014 13:14:41 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf7799499oag.8 for ; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=MSHLQ87rIPGDeOY6/wTUAbYdJAOAu7dx9iyMWMxCzSQ=; b=eB1JwA6xgYORuMKNvnEtWy3zbbP4opbNYkHNUP9aneaIf9nuEclEm/eC6l/9RIUXFL /5Yt820/psX0PRHKfBTkV+umsAfy1Na7+E5Yfiw0diHBVFGqWWSfTzAQ1rJgz24vaoTz +gJzUCILoUWEM5IzxQVYFTfOaixLXc9EQ7isOHF/7D3Yr3IXmewOJVn19v5WJjEJ4O7y x6CkcajqtHRRxO9MTUkGTbGP93Xb/Os3dwU7pBve0845aZZsruIfidBzaJ+uAqUiTymI dFKJ0c4v7zEjPWlOehiXcqd/9iqkJwBzIg8nkz+rjBv7yzYMmpoLpsfru78QLWWtvzUY 3kag== X-Gm-Message-State: ALoCoQk8r6uk7tPK2gFDAVWRXcZG8cZMoWpidyGcnVfPVCIUhe6FvWpfKJXJKRKB89S1QqHY8Oam X-Received: by 10.42.26.12 with SMTP id d12mr2726023icc.24.1409231680747; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.200 with SMTP id 66ls552390qgl.75.gmail; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) X-Received: by 10.52.227.72 with SMTP id ry8mr423187vdc.64.1409231680627; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id ul1si3334900vcb.79.2014.08.28.06.14.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 06:14:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so777366vcb.28 for ; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) X-Received: by 10.52.73.202 with SMTP id n10mr414850vdv.86.1409231680553; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp234647vcb; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) X-Received: by 10.43.70.66 with SMTP id yf2mr4380590icb.36.1409231680004; Thu, 28 Aug 2014 06:14:40 -0700 (PDT) Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) by mx.google.com with ESMTPS id m3si9192622igx.58.2014.08.28.06.14.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Aug 2014 06:14:39 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.213.171 as permitted sender) client-ip=209.85.213.171; Received: by mail-ig0-f171.google.com with SMTP id l13so7977829iga.4 for ; Thu, 28 Aug 2014 06:14:39 -0700 (PDT) X-Received: by 10.50.43.137 with SMTP id w9mr38230274igl.36.1409231679653; Thu, 28 Aug 2014 06:14:39 -0700 (PDT) Received: from localhost.localdomain (host86-152-0-170.range86-152.btcentralplus.com. [86.152.0.170]) by mx.google.com with ESMTPSA id w8sm16633672igl.13.2014.08.28.06.14.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Aug 2014 06:14:39 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Lee Jones Subject: [PATCH 06/11] mfd: htc-i2cpld: Rectify pointer offset error Date: Thu, 28 Aug 2014 14:14:12 +0100 Message-Id: <1409231657-18294-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409231657-18294-1-git-send-email-lee.jones@linaro.org> References: <1409231657-18294-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Checking the result of container_of() against NULL will always result to false. Using the offset of member 'chip_out' to find the start of 'struct htcpld_chip' will result in an offset error when .get_chip() is attempting to obtain 'htcpld-in'. Instead, we'll use the correct member based on a previously the set chip label. Signed-off-by: Lee Jones --- drivers/mfd/htc-i2cpld.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c index 073e180..99b362e 100644 --- a/drivers/mfd/htc-i2cpld.c +++ b/drivers/mfd/htc-i2cpld.c @@ -258,31 +258,18 @@ static void htcpld_chip_set_ni(struct work_struct *work) static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset) { struct htcpld_chip *chip_data; - int val = 0; - int is_input = 0; - - /* Try out first */ - chip_data = container_of(chip, struct htcpld_chip, chip_out); - if (!chip_data) { - /* Try in */ - is_input = 1; - chip_data = container_of(chip, struct htcpld_chip, chip_in); - if (!chip_data) - return -EINVAL; - } + u8 cache; - /* Determine if this is an input or output GPIO */ - if (!is_input) - /* Use the output cache */ - val = (chip_data->cache_out >> offset) & 1; - else - /* Use the input cache */ - val = (chip_data->cache_in >> offset) & 1; + if (!strncmp(chip->label, "htcpld-out", 10)) { + chip_data = container_of(chip, struct htcpld_chip, chip_out); + cache = chip_data->cache_out; + } else if (!strncmp(chip->label, "htcpld-in", 9)) { + chip_data = container_of(chip, struct htcpld_chip, chip_in); + cache = chip_data->cache_in; + } else + return -EINVAL; - if (val) - return 1; - else - return 0; + return (cache >> offset) & 1; } static int htcpld_direction_output(struct gpio_chip *chip,