From patchwork Sat May 27 11:40:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 99832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp280575vqr; Sat, 27 May 2023 04:48:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6PoJPP5QnqFJzhdVLF5kR2u+nbvrqIkcaGqMuoMuRkk9eAqI97/tv4OtwP7bY/DQLBBrx7 X-Received: by 2002:a17:902:c3d5:b0:1b0:2f15:e0b3 with SMTP id j21-20020a170902c3d500b001b02f15e0b3mr458131plj.50.1685188100757; Sat, 27 May 2023 04:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685188100; cv=none; d=google.com; s=arc-20160816; b=vF1dCnUWTFSZNks9nQ5CkFsxZI3+8b/zPikWwNQPG8xqm4OTmOFeSBHFcxk0iq6iqZ Fc6SMrAeQk5l5DWuWbkEqPWvuf1E/j4JmlWbcEvPtUsEzdTCVMF36GSAjRuNNBW/PJEg jHZ7/2ZrE4DdpuGgZnvrf1F6w++RJ57L4bFDQXyOuP4zZlft5lGLIWYo3cpm1h/t3yiN nEWI09K2QucVaShRefbcoi0XC4KW/xSjvY4Viu4Pb73fsYLF+WygsTuxBwRwHKYse8Ju +VsBBcNh+Y1cRmsthtz9TtjignNV+Y7PDYLMUWFgAy+7/1qP2D5XUIskRHBUlfDO+lDH 9JMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gGdCT8339Wa4SZmXr0Qgs9O/mYFTMLPS4wvQ+wDiZ84=; b=sIqR2qglTp8ZVAesYXRCWjX9nNem4xjmxzWm7qW09oBALGXWzQghQ2wXOweRTl9h7z MwZ/Qf+dIBilKf69Pz56H+qEk81/ioEpQpxveTdTJme2LxC4eL5tIJ6ykN0y/7NgJ76x 13KWLcgUGCYA72+LLK5Y7BYuGqu16JImFti5NiT2zv5N5+DyjNY5AcGEh9OK4o7d9i86 lDBdvGNloDrHyfspu8IYguKibKaluDpEzS9qL9mZmWz+bImdQIedcSmM1zgmX78nIWEl hcREmLabRUGMr2dR4nBNTIItvloLXBkmGsv7WsNffk2iNdAnhdUuk6A86mOuX/5KnvwY gG7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oF4qMeDo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a170902db0900b0019ceaf40d5esi2192398plx.107.2023.05.27.04.48.08; Sat, 27 May 2023 04:48:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oF4qMeDo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjE0LlB (ORCPT + 99 others); Sat, 27 May 2023 07:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbjE0Lk7 (ORCPT ); Sat, 27 May 2023 07:40:59 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4C3412A; Sat, 27 May 2023 04:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685187657; x=1716723657; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=QC4EyfXO3AcM4/0Pzq8plC2mDQ7iHdK2qw8lFxVpt48=; b=oF4qMeDoI9PhvN9xgSmqiDN1AJpljJa1367Xs7eOkJ8LRA7jQiX2PXtZ LyvnDJzRN+VkrL0qcrwXB6pkTgV98CnZ2lcS+kFr4qUHubknuIBLBYC9N 5t1Lq7azEGaAbpU07vcyfdRWOYDbhBBQj8PSH5EON7YEl3lXvvamq20er scpOsWE71YtWiC2tCAJ8+T/sI1/YGV33gMt4fVmlsdSQmj8YwGLVqEd/W 8aw0F20wokPVCHfzEjSyao82prw/lqUaqwudwbjSoWttD0PlUDqrtzGo4 ZNhtdCFWt4tDgtToiStBnwJgUHBZYuHVOPOXT6nVcghC0Pbb7y07JClpy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10722"; a="420148079" X-IronPort-AV: E=Sophos;i="6.00,196,1681196400"; d="scan'208";a="420148079" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2023 04:40:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10722"; a="699685247" X-IronPort-AV: E=Sophos;i="6.00,196,1681196400"; d="scan'208";a="699685247" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 27 May 2023 04:40:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id B293240F; Sat, 27 May 2023 14:40:59 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 1/2] gpiolib: Consolidate the allocated mask freeing APIs Date: Sat, 27 May 2023 14:40:56 +0300 Message-Id: <20230527114057.36091-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767047798069456793?= X-GMAIL-MSGID: =?utf-8?q?1767047798069456793?= There is a common API to allocate a mask, but more than one duplicative counterparts. Consolidate the latter into a single common API beneath. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e62db4fc85cc..6c8580d2454d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -466,6 +466,12 @@ static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) return p; } +static void gpiochip_free_mask(unsigned long **p) +{ + bitmap_free(*p); + *p = NULL; +} + static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc) { struct device *dev = &gc->gpiodev->dev; @@ -545,8 +551,7 @@ static int gpiochip_init_valid_mask(struct gpio_chip *gc) static void gpiochip_free_valid_mask(struct gpio_chip *gc) { - bitmap_free(gc->valid_mask); - gc->valid_mask = NULL; + gpiochip_free_mask(&gc->valid_mask); } static int gpiochip_add_pin_ranges(struct gpio_chip *gc) @@ -1090,8 +1095,7 @@ static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) { - bitmap_free(gc->irq.valid_mask); - gc->irq.valid_mask = NULL; + gpiochip_free_mask(&gc->irq.valid_mask); } bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, From patchwork Sat May 27 11:40:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 99833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp282070vqr; Sat, 27 May 2023 04:52:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7eCuI4G4lAMu7aTPhfAiAZ5dNFLMet5EnlI47uj5RHh9pdH3j1tgRdaSunqeVGS9hGOpyg X-Received: by 2002:a17:902:c94f:b0:1ac:750e:33f4 with SMTP id i15-20020a170902c94f00b001ac750e33f4mr6303020pla.32.1685188323208; Sat, 27 May 2023 04:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685188323; cv=none; d=google.com; s=arc-20160816; b=IoZHRMkb5FTq5b4d3AlX1s1lV8X1mk2Nkl9GfVGIXRtPrrwTgI8I6sW4O3HrNAcu+9 FZ/uLPMwE9jP0YooJZHek8EqzY+ehVursat1bfhDb36WQvxzb/GugfqQf3bsURlNySMa kL5KVrgdWjge5wx2hCjG6qSqXlzlNF7ZWYm/QRa8IKxrU28l7j4YTEdyz8aNxj4UqZCB ZAQlHgnMhsGnlXXKsruFb8L/pZpVXkgsHGxTZ05BJvtzA96JNUTo5gIl20lKiylOOz56 bfUM8Pp0FrOCRUasvyNY7cGNcEb9zMlbHCHr7C27Ooe83DdGYQgZjf74LSTgnkCTrB38 avcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/z178K0sNYbCi9Bbg8kFPVavCItapTvTkSZJ2ozl/1E=; b=fo0PjLBBAq+BZF3TnbcW4GkbP36z72V0gRrD6x1auqCLO5BA/tF0oWiFnVPJcjVC5B d3yu0gNvfWtLpyyEMU1aGrSIoOjBRPBdgfjOMMVRRE8Mui14Q83pQs2i+CJgKFvbVh3H 9JlzjGgGERFU3/jdsGHkqhfAx3z3+KjpKE++dQfMaYt4FJ0dvk0vZvkkQCxezw4WGfRU HYOOsoq7gRD9K8TT6Yb9PEWInWHgi8RdRsfc4DnQZ3hEjeLh4uSmmjpFONF0KVaBNf4E UmNQjNt2pe8R1SFe22mEepWEil0F9vIzMVE/Ruq4p8ESCqf6TgheInYkKs96riLTbQbT FS+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NZ7y2lET; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a170902779500b001a197aa18fesi5910883pll.121.2023.05.27.04.51.51; Sat, 27 May 2023 04:52:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NZ7y2lET; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231436AbjE0LlE (ORCPT + 99 others); Sat, 27 May 2023 07:41:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbjE0LlB (ORCPT ); Sat, 27 May 2023 07:41:01 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14D1699; Sat, 27 May 2023 04:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685187660; x=1716723660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8vQhV/X2uljI2SaCtDuLjSsVmNOvaJBWIYyBH8FBji0=; b=NZ7y2lET+XTvh2a+On+b21gdgiKJQSNv74mPf8qRTuxCVHOJ3kh9NZ/t 0YRiX7eRVBNdykoW3erlQcBDm+ZxPvkGyUjXphv0kH9Q/mPJj2Nv0zY5S 6FWOYOE4Sp56WB9y6qJwhl6Udba5cS02w/lpC02yektGDm63DJZm6T3Xn pGtor+i1AFTwP2To2RRwXE5y0EBk5fR3hOloxGBERBVfgsz85RA2bjpT1 4eP4LSiFfBPupDSMCW/n9CPf8chEeR6AndhS6nIQo1q9cPQstpAfWbogc Sk3OfoEgSgoZy8rp/uQQFiL59EzBD7h6WjMWHMq8oUJWgYYBp0P2FtsxI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10722"; a="420148086" X-IronPort-AV: E=Sophos;i="6.00,196,1681196400"; d="scan'208";a="420148086" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2023 04:40:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10722"; a="699685259" X-IronPort-AV: E=Sophos;i="6.00,196,1681196400"; d="scan'208";a="699685259" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 27 May 2023 04:40:58 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8D4B0413; Sat, 27 May 2023 14:41:02 +0300 (EEST) From: Andy Shevchenko To: Bartosz Golaszewski , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski Subject: [PATCH v1 2/2] gpiolib: Unify allocation and initialization of GPIO valid mask Date: Sat, 27 May 2023 14:40:57 +0300 Message-Id: <20230527114057.36091-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230527114057.36091-1-andriy.shevchenko@linux.intel.com> References: <20230527114057.36091-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767048030978385406?= X-GMAIL-MSGID: =?utf-8?q?1767048030978385406?= Now that the of_gpiochip_add() doesn't use valid mask, we may unify GPIO valid mask allocation and initialization. With this it makes a symmetry to the similar which we done for IRQ chip. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6c8580d2454d..02bfe0f89871 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -485,18 +485,6 @@ static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc) return 0; } -static int gpiochip_alloc_valid_mask(struct gpio_chip *gc) -{ - if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask)) - return 0; - - gc->valid_mask = gpiochip_allocate_mask(gc); - if (!gc->valid_mask) - return -ENOMEM; - - return 0; -} - static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc) { struct device *dev = &gc->gpiodev->dev; @@ -537,6 +525,13 @@ static int gpiochip_init_valid_mask(struct gpio_chip *gc) { int ret; + if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask)) + return 0; + + gc->valid_mask = gpiochip_allocate_mask(gc); + if (!gc->valid_mask) + return -ENOMEM; + ret = gpiochip_apply_reserved_ranges(gc); if (ret) return ret; @@ -863,7 +858,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, if (ret) goto err_remove_from_list; - ret = gpiochip_alloc_valid_mask(gc); + ret = gpiochip_init_valid_mask(gc); if (ret) goto err_remove_from_list; @@ -871,10 +866,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, if (ret) goto err_free_gpiochip_mask; - ret = gpiochip_init_valid_mask(gc); - if (ret) - goto err_remove_of_chip; - for (i = 0; i < gc->ngpio; i++) { struct gpio_desc *desc = &gdev->descs[i];