From patchwork Mon Jan 28 15:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 156801 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3691608jaa; Mon, 28 Jan 2019 09:35:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ixGlQU8g6uBGUwMFNm88T1Nh97s9PnfE0SivBbHYJ3moDpnt3faZCqqR03D4dVxuRsI+c X-Received: by 2002:a62:cec6:: with SMTP id y189mr23611762pfg.100.1548696952746; Mon, 28 Jan 2019 09:35:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696952; cv=none; d=google.com; s=arc-20160816; b=byGGp4w+08+aRJSv0sBn0ePjSmmhYFyqx0C1HdBj1Tyd6x3jT8a7YiRXdpFGOcSh6b dUVk8hwU+TZZkl/Vi7Oif3ZybSdzBjmxSIbarR0++Hwna1g3QzjEYgiysUwVGnHV/kaK FHynzBnM/srCi18iGUnDBONI8WFJo7DUdAKiTG6rozVs9h7Kn5K2t17TCTcDsICdI3B/ t5GPvzSA9akIoMcJkxwjdQV4n94gLw1u1HNGZxELDrkreBgmgpTrfMwHc8RtpQu43cvI JCFdLRIUv+mH+pwLcZFJ2FAGu2IeuKTFKMjPaGkRPEceQZ2iahqb2rzpLAT2C6kr1WmN Y3sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y61FLzvMGwuY8EhkE3hjek/pc/s87AiM7Lg6ZKyxvx4=; b=Ks5zOYa/wqfa5bFluuzoWZO84G/IK6ujlM1FAmwM2pwLd60psjJfDH1npNgMUkF4F3 i2R0+MTtIDJkFlJOhxXMkN2p3AHJ9uLeuosWh7B3ETvhUyDI6fdd6eThGFaefGnLiNfO mYgv7jtOseIGjsoiqv45wDCY1cKp1fH/qPp5abyek4FEzVwR7YJzX0M8FbV8VhkMsmQs zaKeqSB+eyKEcGEYgeFZYyD9+ZMjZVTvL3/2saxAxg+F0ZVnkyUT07vnO+Vl/JMmheWg v+odcFlIxdeaC42jj6kjZgZ8Wk7FkYkfIEk2f4xzyqt79Z5PPiJpITXxzP9+hLlLg5v6 vfhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PAJPA0PE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h188si33266524pfg.44.2019.01.28.09.35.52; Mon, 28 Jan 2019 09:35:52 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=PAJPA0PE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730708AbfA1Rfn (ORCPT + 31 others); Mon, 28 Jan 2019 12:35:43 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45650 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729872AbfA1PzU (ORCPT ); Mon, 28 Jan 2019 10:55:20 -0500 Received: by mail-wr1-f66.google.com with SMTP id t6so18578830wrr.12 for ; Mon, 28 Jan 2019 07:55:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y61FLzvMGwuY8EhkE3hjek/pc/s87AiM7Lg6ZKyxvx4=; b=PAJPA0PEon0lTUGPXRPrGfxDPtCfSY3yMfUz5KR6fsjS6OccHlcjx2Up2RA7cX+3Iv 4SwIz4Xvs7Dig4ulvTR/hKXAiebOu4POKXv8sbcp/FEbrT9OXCyWCDYTxyHqIjrpNRXE lNjDPjhgsSkP+A40JmE7Bqdh5O1w5pPHujeog= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y61FLzvMGwuY8EhkE3hjek/pc/s87AiM7Lg6ZKyxvx4=; b=A/tqGzAV6ORuZ8AR4iDut1muRhkkY58NelQbOA3Xez797hZD3axA1nFh3xPB0KsRjJ bRqnb6r5mg4nAoEPDmQZRXkEewAVojECYJmoVZh4ZtzHrEWtJ5gJxUSdwTkMxeam3R9i bdoPFK5es3gKvEhujvD8z7UZ6PjbEchmjHZvITtvKq9Tv+BELDbDogzB9M0uhn+v8uT6 DpCLQgfd19QYFyF4GRKnW0/y7DXpvN2cXcP5pZnyp+rEuMGEiBEpDSXybkQ9WGAgw6gT RVk4CBsdkPzs4ComHYmsLVbNx1XBowaYFR2Je4ddOxKrTO9SEcsORphJiDb8RsBZ8ijE K0aQ== X-Gm-Message-State: AJcUukd4Ek0etLspRIW1scCotN9ne2pvvzYtP+YU51rWura9d6xanoHJ jFwnXwYSoR1/pzgfuE56jVPERp2qT3c= X-Received: by 2002:a5d:5208:: with SMTP id j8mr23115456wrv.188.1548690918427; Mon, 28 Jan 2019 07:55:18 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id p6sm145140485wrx.50.2019.01.28.07.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 07:55:17 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 09/13] nvmem: core: Fix cell lookup when no cell is found Date: Mon, 28 Jan 2019 15:55:02 +0000 Message-Id: <20190128155506.25566-10-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128155506.25566-1-srinivas.kandagatla@linaro.org> References: <20190128155506.25566-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alban Bedel If the cell list is not empty and nvmem_find_cell_by_node/name() is called for a cell that is not present in the list they will return an invalid pointer instead of NULL. This happen because list_for_each_entry() stop once it reach the list head again, but as the list head is not contained in a struct nvmem_cell the iteration variable then contains an invalid value. This is easily solved by using a variable to iterate over the list and one to return the cell found. Signed-off-by: Alban Bedel Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f8c43da6f2ca..a2ad44104aa2 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -525,12 +525,14 @@ static int nvmem_add_cells_from_table(struct nvmem_device *nvmem) static struct nvmem_cell * nvmem_find_cell_by_name(struct nvmem_device *nvmem, const char *cell_id) { - struct nvmem_cell *cell = NULL; + struct nvmem_cell *iter, *cell = NULL; mutex_lock(&nvmem_mutex); - list_for_each_entry(cell, &nvmem->cells, node) { - if (strcmp(cell_id, cell->name) == 0) + list_for_each_entry(iter, &nvmem->cells, node) { + if (strcmp(cell_id, iter->name) == 0) { + cell = iter; break; + } } mutex_unlock(&nvmem_mutex); @@ -994,12 +996,14 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) static struct nvmem_cell * nvmem_find_cell_by_node(struct nvmem_device *nvmem, struct device_node *np) { - struct nvmem_cell *cell = NULL; + struct nvmem_cell *iter, *cell = NULL; mutex_lock(&nvmem_mutex); - list_for_each_entry(cell, &nvmem->cells, node) { - if (np == cell->np) + list_for_each_entry(iter, &nvmem->cells, node) { + if (np == iter->np) { + cell = iter; break; + } } mutex_unlock(&nvmem_mutex);