Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5281247imm; Tue, 21 Aug 2018 09:05:44 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzX+4x2sXK6cwcLLHESYg5KmJlq/QN46cdOx+CGUTYzpH7EEsFjTIfbXBRi5YSvpNVgSOOk X-Received: by 2002:a63:5d4b:: with SMTP id o11-v6mr11443317pgm.349.1534867544830; Tue, 21 Aug 2018 09:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534867544; cv=none; d=google.com; s=arc-20160816; b=DOdhONJS368tFkWsQMUln2lbk8cnvvkvck4N3BGxCkxjEnvb5Qnd37T5wClbljw8JT vSRhwaaOuRSxxwRrihj3Lr8W+CYxHsZ2bpa6jHJ4x+x0WKIXW8+Z3Z1fNl4yeLVSjetM a0vcis1lSAHKoTn/ab+hw1QHC5+j8LR2vsFl349Y2Zr1uFszu/IcKx58gU0Y38MQE4nx 6Anu3o5b1/JLQdoeHC2fBCZP/YbvnQ6ehc8/0r8aHD2bGuXtu0C/MxpiIyrubylEg3F9 b5YRrXvT0o+JinBuj+N7SfRNa2ECivMyqhnfzUGLSgu8x3oMoDnJMuW+HvwifiQp3NeQ 6UdQ== 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:arc-authentication-results; bh=x1X9SeLxMkYUfY/VqyIygkrF9CnPm2MQCzqigX/Lt3w=; b=Ctc3NDx9sHznRWkwoVr+xjJdM5BHMT3YfL/ugBXoeYTidKXhYATGjNqRX6u+GA7c/t 889OZLOHFSeWa1/g66fk7zXUOW/wQzhtj4L0z9rNDvIB8dI5raNUmzBmh0zFHx3PjgMz DhAsNqbY490u8Jf+69fa9XL2PaufAeGQcpE3GG6jwvitdSUZ2YkzkpGPHwg9HW6yXilS TnSJjD2G9UWweGaLQoqG6in8mRqySiKBSN/NginJfVMfaQuLrVJ4OEQUifbOEKlw+DRc dWi+Voscr/16qiYxqyRf1YWOvjjSl+us1tF4gWEsULfK6IdaWfgbQeHA3AQx1UUiOLIf jCJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gLIyWtea; 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 p64-v6si12502878pga.25.2018.08.21.09.05.29; Tue, 21 Aug 2018 09:05:44 -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=gLIyWtea; 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 S1727668AbeHURwc (ORCPT + 99 others); Tue, 21 Aug 2018 13:52:32 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:44947 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727611AbeHURwb (ORCPT ); Tue, 21 Aug 2018 13:52:31 -0400 Received: by mail-ed1-f65.google.com with SMTP id s10-v6so3431050edb.11 for ; Tue, 21 Aug 2018 07:32:08 -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=gLIyWteaqT/TgLGRTo7FYQOxVVTJSocdkmiXfrhUOjPzMiHeLmY3OoQpwo7mYuB63X V2AQFPPx+xV7UVobbdxuTjHfFfSQWdhGbjO7rTNIOaX8B5zrRZMu7UTe/LtVGpaFHYZY qLPtKHPw5MWwAZlGJGefHkBVL55ZEOlI3wKOvmXa0ZApfRuRS6eCdYLB/zkniChJyq3J YKluWNsyoX+piy69osoEILenU16MVwMiD6JLNBgUU7FfmX9HJgs6oUMPJSZpOJVnccJt VNUDi83grLLhfuTrKNLqEKNe9NvqVswIqDf9gb5k9bxHuWpAzUNwIkeNd9N4CssI34A0 WMwA== 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=rsIOjFKdGm+CfhqqQxIzKxRf5hzzT0ulE7MVLHTjZaqpnhckoDPUFoSZSDHC5jH8eo JnXZe46jr+vD2/0roMkH1JPxxXweYNETpLjQnvUEmmkCIVAAAMTKCJzrH4DqgcLkFiUH NoXrAexVujsF+7SJxgWKJ0UuNzl5+gpIlLDLyisoq5ig/6HS7qWoZjSABuG9RMfjidLi HFk+leUyxkzA9ZeO+b24jeYI5HPtjo6IN5/V0RiFOoddVSmlFEX+njcNKymKpoB+MTSU rRmXii0ZWIrmdV+w/aDeCIp2ppQwd/s0GKfF0EYCGX8fK9IzcNK9y1u2aubu7T4p/l7l qCTw== X-Gm-Message-State: AOUpUlGeyVUADR/fRN2+mw6Y8w4qRFB11cAy4J8aBryqn/TG7evYtDCy ExoWSIB/ZB5FflQn2gMN5PA= X-Received: by 2002:a50:8d5e:: with SMTP id t30-v6mr9061625edt.256.1534861927560; Tue, 21 Aug 2018 07:32:07 -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 n17-v6sm6766144edq.10.2018.08.21.07.32.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 07:32:06 -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 Cc: Ricardo Ribalda Delgado Subject: [PATCH 6/8] mtd: maps: gpio-addr-flash: Split allocation in two Date: Tue, 21 Aug 2018 16:31:50 +0200 Message-Id: <20180821143152.32293-7-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180821143152.32293-1-ricardo.ribalda@gmail.com> References: <20180821143152.32293-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