Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp88360imm; Thu, 4 Oct 2018 23:53:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV60z18oc411kYjCrwsU+Mx/X7J1/V7bdh8JBeCnH2NJRBJ1mUa+pchMpCA0/NQFjX2NXO76l X-Received: by 2002:a17:902:8d82:: with SMTP id v2-v6mr10344877plo.9.1538722414783; Thu, 04 Oct 2018 23:53:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538722414; cv=none; d=google.com; s=arc-20160816; b=h4bYiY4tuuadp0AtCGdUTT/++252RLdgaHRGi45yHt7RJ/DH7wRaKo+mtzs8KkcgbS zvp9vTfV97fCSi6qIPlV0pqy2eeli8gLLlur71kTZ1L+AWfcJ4mGZZaKOkp7200aO0D3 ygGASYsZFSkablnITqH6pAbYPOCuTRfkyh5ZIXCWTSXkBlT3mv9ZunvKAcxZ7Jh1s2Tt buUxHUVFGyAQTu4ML+ZeqRhcmDnDQ+VVzl0FG67S/34FSBbC6/BJHjWgGSwfdq+LMKim 60ZDUojlLQ02vMf5nOIkLUexiX84s48MsK0CWbXChZ5S9bUsBrNiMngRJYjQHheJXkNy 2ZnQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=xBWJIuKG25fJ3c03nNo4vLlqJ9Gh+jksa5pKMeO33sQ=; b=poUrUgcqh6a1SXRQTBJuzfMOZXnnt8hggNXpA5VwrNGQl7RzoUDHaz81nST+LBljN0 KilXmGE1zXTvDIch7hH78M8Sfv751rOYQ+1sAUlNxn8pvtiHo3VfM82luG/ZTC7+Rng0 RRSuiZl0V0lZu/tuBDxFcmEQnhkxofh7QjwpGwiZCtSIe1UGCS/XAf58yHDJNz5Tyzqm 0HiMqVnlSCSM+QAAneHNMDrOEaMsAxCHia0KAi29GYQppJksIgA2WvAXZ+T6GVYvqJSn 6GIx4PjKrHkZqCnx4ka2OAmo5vOA6hUo0MMvrWO/Aj8hf5DAuoyF3GHFCkwGZM6993NX 2HdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bIT98nUU; 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 e12-v6si7413154pls.389.2018.10.04.23.53.18; Thu, 04 Oct 2018 23:53:34 -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=bIT98nUU; 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 S1727962AbeJENuW (ORCPT + 99 others); Fri, 5 Oct 2018 09:50:22 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:41728 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727025AbeJENuV (ORCPT ); Fri, 5 Oct 2018 09:50:21 -0400 Received: by mail-lf1-f65.google.com with SMTP id q39-v6so8571567lfi.8; Thu, 04 Oct 2018 23:53:03 -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:mime-version :content-transfer-encoding; bh=xBWJIuKG25fJ3c03nNo4vLlqJ9Gh+jksa5pKMeO33sQ=; b=bIT98nUUew3kkIXuTPrzGSYrqTcwl3zEqkgvrfvMc0yStMYxZc2KBtR/8PYhD8/IvF MA5tharguvnUUPBaHO8xm2MHKKCBXhbrpC7/fNAhwkF//n5gCWxmuVcHtI0zpdoQY0N0 d3VG2QAeXaDOcu0lP6f59W88xJ/iaClZX7+CGnm5KWykNX6z++fREgVHvUCoElLJaQQJ 2zOSIaHUKvG1UBTx3uzqc2CdhSF8NrX1fFyllMCe9zJc0jv+JfKPgRsUVENAaJgOb2RZ mu/RMqlr763eJZmaurwRlH4pxcftTrQ4QTalcuVTTgdWauVDg4ViihJ5hEx704Iimwxj zbWA== 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:mime-version :content-transfer-encoding; bh=xBWJIuKG25fJ3c03nNo4vLlqJ9Gh+jksa5pKMeO33sQ=; b=K8sKzlplVW9Z7Pp3aG4va/fHC0CGIVSlDBEOaRfDGRYcjF/uWqCMSA/MPZajxzA6bY SItTNFVAUecCZXXA+jSxhpMw+rCWj8nNx6VXAxZnhpJG8P42JUELjYfVxs0gkrxX9UhI S6EzMyZ9N1sIxy0wHHN3T1L+LHxP5FDW2iT1msaO5SA2NKTkzsS8mD0XjJIGTZPckJPQ IezPlvxXPzEhy28Z6RTGa0MaWLzY8qOPse9C4ChCeGc0Xpt3E7vo91PzdnicFnznfEXj gjHsDsw4jMWQfhddYqi73ZOzIPHaiQocPyVfRoDeRCnkC90j2zKDf6dfj6p+G6I7wBey aG7w== X-Gm-Message-State: ABuFfogdns15U420ea/BNLTRFQ7b5VvTbKnYEa+Tt3WLoaWN5LsxJeL3 Dbz50TIOGnTQHvI+Mbhlgdo= X-Received: by 2002:a19:169d:: with SMTP id 29-v6mr5622722lfw.151.1538722382592; Thu, 04 Oct 2018 23:53: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 t21-v6sm1608871ljg.32.2018.10.04.23.53.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 23:53:01 -0700 (PDT) From: Ricardo Ribalda Delgado To: Jeffrey Hugo , Linus Walleij , Timur Tabi , Stephen Boyd , linux-gpio , LKML Cc: Ricardo Ribalda Delgado Subject: [PATCH v5 1/3] gpiolib: Add init_valid_mask exported function Date: Fri, 5 Oct 2018 08:52:58 +0200 Message-Id: <20181005065300.22882-1-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function that allows initializing the valid_mask from gpiochip_add_data. This prevents race conditions during gpiochip initialization. If the function is not exported, then the old behaviour is respected, this is, set all gpios as valid. Signed-off-by: Ricardo Ribalda Delgado --- drivers/gpio/gpiolib.c | 16 ++++++++++++++-- include/linux/gpio/driver.h | 7 ++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e8f8a1999393..907019b67a58 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -359,7 +359,7 @@ static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip) return p; } -static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip) +static int gpiochip_alloc_valid_mask(struct gpio_chip *gpiochip) { #ifdef CONFIG_OF_GPIO int size; @@ -380,6 +380,14 @@ static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip) return 0; } +static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip) +{ + if (gpiochip->init_valid_mask) + return gpiochip->init_valid_mask(gpiochip); + + return 0; +} + static void gpiochip_free_valid_mask(struct gpio_chip *gpiochip) { kfree(gpiochip->valid_mask); @@ -1367,7 +1375,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, if (status) goto err_remove_from_list; - status = gpiochip_init_valid_mask(chip); + status = gpiochip_alloc_valid_mask(chip); if (status) goto err_remove_irqchip_mask; @@ -1379,6 +1387,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, if (status) goto err_remove_chip; + status = gpiochip_init_valid_mask(chip); + if (status) + goto err_remove_chip; + acpi_gpiochip_add(chip); machine_gpiochip_add(chip); diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 0ea328e71ec9..df09749269ff 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -256,6 +256,9 @@ struct gpio_chip { void (*dbg_show)(struct seq_file *s, struct gpio_chip *chip); + + int (*init_valid_mask)(struct gpio_chip *chip); + int base; u16 ngpio; const char *const *names; @@ -294,7 +297,9 @@ struct gpio_chip { /** * @need_valid_mask: * - * If set core allocates @valid_mask with all bits set to one. + * If set core allocates @valid_mask with all its values initialized + * with init_valid_mask() or set to one if init_valid_mask() is not + * defined */ bool need_valid_mask; -- 2.19.0