Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3893762imm; Wed, 5 Sep 2018 07:38:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYX8UyBO964eMY1nlx0m0b7X4Qbrv+uuMFAZfzz0aWMBqoW/kQq6bp289dDA/HZ46iwYhT/ X-Received: by 2002:a17:902:6b89:: with SMTP id p9-v6mr38716132plk.272.1536158326249; Wed, 05 Sep 2018 07:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536158326; cv=none; d=google.com; s=arc-20160816; b=toiYPmOfY4Bw0expwW9dgZQXITeXpjuccKmXSDESY+giC9oJfzg4+X054VOqHo81Fj sjbciYrY1ObvP+Z6bG2Ugw6ukhOSlpbJrRsoeW48xOnpDSupmhmMLhen9820E29bN3JK oZzZoeDjmIPyqn7xbVwYcuPXqsNo5ek12XOucJOTKc+drI2elEns+hmiYN3aSECVZQ/4 hKghzjBZeaiAbdmtmx1AaLHaDyHQIIe3bKL1+Cy0tpFOKW5g2xk/Rd+1FIAqTgZACXA3 jxbKrDI/pouCk3HgTmGSJDiHr9nwWV4SVMibnlyFqjTvhVAC9ZZgJKL59AP5NW/sg1vk waOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=x1X9SeLxMkYUfY/VqyIygkrF9CnPm2MQCzqigX/Lt3w=; b=niPkEoJZwr/cKeEYb/ksEFHbcm5fKdNKrB73wfiq5mSLt8XI6FwP92QiXapxu21rv3 mZPbk4uQFLvXy42xYS7OdlRHBcar8VjqKL4mQTXD2wBLnLuqMUQjOZH3p9p5yoabZ+Sb aRlPJwKRFIqwKJ+u2nuH2GQflKn/jpZ2D8aVBojWDg9Ax2rt4NY/qBdFIgrkw58hWyXO boO/RpnIM+5Wqcj94mO2iGRPfJPDxMUYThpfaIsfzY5tYTpQ16cBP5WVsR3lrrHqCMj2 dh3gdMfdUETsjn4mTKUn8j78nXf459ZtTKOn/RfbumLNzXlE/HOM1iTI+o60Tt0+wpDf cVLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IbE6S6FC; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10-v6si2283814pfb.316.2018.09.05.07.38.31; Wed, 05 Sep 2018 07:38:46 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IbE6S6FC; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727840AbeIETHc (ORCPT + 99 others); Wed, 5 Sep 2018 15:07:32 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:43294 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbeIETHc (ORCPT ); Wed, 5 Sep 2018 15:07:32 -0400 Received: by mail-ed1-f66.google.com with SMTP id z27-v6so6265427edb.10 for ; Wed, 05 Sep 2018 07:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x1X9SeLxMkYUfY/VqyIygkrF9CnPm2MQCzqigX/Lt3w=; b=IbE6S6FCGe9id6Cxtizw+sLo1JChbA5CmLBhDoQB+/BD4zmZMIuij+l9PIwOkgWoez 7u0yi00GxSqk6jbMS961ktz+RUoB2YVyjiZ3xuF7eaXgS1kMJ+QKsLlUENo+sQRhzK7y yEmJR5f4k4x1aBmXx3XpmV7nPKLvExZrxvnxvu/4iLZZtZ2VODcXwdTSIQj5CheEPZRc VpW3BJX3lboFwxd/npNF/gPzP3lt2RQ3IbrzJgBJBdnirkqOkX/z+RpwU8xVLLIDjjju 9pl2kGox0fPYZuB7cYWPAxYRSgirhSWdagqkFQWDQR5Jfat1bLANatM2LmeOS8Kc6D8l Yiwg== 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; bh=x1X9SeLxMkYUfY/VqyIygkrF9CnPm2MQCzqigX/Lt3w=; b=rRB1YL/rjJOsQ/59hLQvFhs7qQecv7ZBFw6lEbxNE0lZEFta2nvrZhGTJMeG0BN/U0 ysD1dBrmEEf5KzL9PFvUJlq7XlXEemH+SmqayBsZuBakZrB771Mo9IHpy6WmlRrxfAal enNxXNHm7Ilw+1NrrMJy5MtsveRUyuN0VFssqhgwglIeiAAtJyxC8/1Wsa8gMAEuaBqJ 8JbQRwjOwhSNrkspql6x08GWQUyJPk2ZVMIGtQ5099DeygayzLa92zuxQDwkidvioWTn bHZGFQZWPd7vHRTyb74iWMTW3eqFLmj3SoAA1mbMXlmrSpChsG8rGy0LRY5RuZcvs0YX 2oog== X-Gm-Message-State: APzg51DlZZjLL9J4PsBqwSKIDdUo6eUvnD+t9DJKXGfhL+wt3IxQDLuo qpQJAZQ4Ak2GHAYY1MxSY30= X-Received: by 2002:a50:95dd:: with SMTP id x29-v6mr42974402eda.3.1536158222271; Wed, 05 Sep 2018 07:37:02 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id u53-v6sm1556413edm.51.2018.09.05.07.37.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 07:37:01 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Cc: Ricardo Ribalda Delgado Subject: [PATCH v2 6/8] mtd: maps: gpio-addr-flash: Split allocation in two Date: Wed, 5 Sep 2018 16:36:41 +0200 Message-Id: <20180905143643.9871-7-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180905143643.9871-1-ricardo.ribalda@gmail.com> References: <20180905143643.9871-1-ricardo.ribalda@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of making one allocation and then calculating the addresses of those two pointers in that area make two allocations. This simplifies the code. Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/gpio-addr-flash.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 8f5e3dce9be3..9455a8448064 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -205,7 +205,7 @@ static const char * const part_probe_types[] = { */ static int gpio_flash_probe(struct platform_device *pdev) { - size_t i, arr_size; + size_t i; struct physmap_flash_data *pdata; struct resource *memory; struct resource *gpios; @@ -218,8 +218,7 @@ static int gpio_flash_probe(struct platform_device *pdev) if (!memory || !gpios || !gpios->end) return -EINVAL; - arr_size = sizeof(state->gpio_addrs[0]) * gpios->end; - state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL); + state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); if (!state) return -ENOMEM; @@ -228,7 +227,12 @@ static int gpio_flash_probe(struct platform_device *pdev) * away their pointer types here to the known types (gpios->xxx). */ state->gpio_count = gpios->end; - state->gpio_addrs = (void *)(unsigned long)gpios->start; + state->gpio_addrs = devm_kzalloc(&pdev->dev, + sizeof(state->gpio_addrs[0]) * + gpios->end, + GFP_KERNEL); + if (!state->gpio_addrs) + return -ENOMEM; state->win_order = get_bitmask_order(resource_size(memory)) - 1; state->map.name = DRIVER_NAME; -- 2.18.0