From patchwork Thu Feb 22 09:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 204655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp143485dyb; Thu, 22 Feb 2024 01:50:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUiZ3YA/W1LUrZvfmJ61S57/81Ea+FIb+Ao9pfbTZkdat0LhdEqWog5I3JaYDzU8XZNZ9rVp5NRS7W2SUPJ+iPAAyEDjQ== X-Google-Smtp-Source: AGHT+IEn/TQY6rO2xU6mgGiE/MtmWP4iLSAXW2imGM2rxQUGHKsl9p8JibkA+hqfuv6Qy4Ua0Bgr X-Received: by 2002:a17:90b:14e:b0:299:43fd:e967 with SMTP id em14-20020a17090b014e00b0029943fde967mr3036552pjb.18.1708595455739; Thu, 22 Feb 2024 01:50:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708595455; cv=pass; d=google.com; s=arc-20160816; b=gSNMnstmPWlJcuHTDWxmr+8MoHSLtXkF0F3JOQAtr9njDU8rZLtyXCFGtuQ6IM3H3a bNxfKCAX/9kKRL2mP1V7N5afHmDa/Kcx9TFxDB3t9MCugIDZQoBn8rjq8M1H5Dg9GEpP oJbA8Z9SRwx1z6eWBnYUq6PgNCYjUwBY1RdikDjnnjGTncNS7DyeJDnF13lcPx6YjTjx 3F/IiVe8Gw39DYWSilyaFA2SuXGFp4W8P5ms2j7GW9hcxOq/6enWNVuCXoZHJNG9vHG6 M5TQTGfYBHyAyfkQEOIoKLq79vkJzksvv1T5U5zem9qfAr0MJ+QyjRcKc0OugoEnMf/j giHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4Mzp7gOUhADSPQHe9BbGbbZnz24qrFAsUkCIt0RA8CU=; fh=7e+22GdnXH8HvfoJb7BQVk49msx/hSOvNNVqjJV5F+M=; b=Aj8KJH5k0DyNFn404ao5yOUyQYnG/HgYjkj/hnEHaOIhw/VmMId/RIQN3a7IzqGz6p 5LI7kh1vCwN0/pnYqdlhz1vPfQy4lm480LBI+kL+IxyIxiFhAGKSBApeGU9CiXz8bUqf 0HGeBlxPDDQQDZaVYH/ugmvNTqFuisPygE3TXRxjbsVE6rh4abZ2hOSQXj9aLMpg+8Y9 MI7cm/W0ml33CJlRjS0fQu/BDPFvFvL8zqTuJ2REA3cnwX1vnZXDUzvx6+j4/VUqfNKB vsi7pMFujOAZ08s5IVpC1K0wPREtm+0ZGi50ejMM9zF2AJzu2ZtQIR6pYlj7H0QzKFUe K7Og==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="OQ/Hvd7l"; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-76240-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76240-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x15-20020a17090aca0f00b0029a19777c30si2708824pjt.93.2024.02.22.01.50.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:50:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76240-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="OQ/Hvd7l"; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-76240-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76240-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E116AB26786 for ; Thu, 22 Feb 2024 09:41:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF9D83B19E; Thu, 22 Feb 2024 09:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="OQ/Hvd7l" Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 781CB38380 for ; Thu, 22 Feb 2024 09:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708594844; cv=none; b=aYiJbT9VkqFDeFrCw1asjf5S3xpn67dAxmH1s1P+vXwNyxmyUVq/DliR2qtXJf/rqimSoeghg8bNb4CMSjKncJP4VbYUXWXxpHf5FqfrhPAxwYw/gbmyS7MmROELVQ2iKn8v8swmm40cIVzl/sLy6jgCz1LoO3sNEWT+9TKkQYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708594844; c=relaxed/simple; bh=FXoCaba3gtvEALwRNM4h4nFnfI8O68CksmTNcI5rPr8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZrEoDzCNzWQJm8NrItdnbz37WONefWhQfPNnvaA5ev8q+b1slIIADrQ9ZUpT0mNNeXnWNrd2mgZxchK7ublakaMP/l5Kwh0StOSdPRcLOb2UbOJRgOkgj1r5ZQA4+uffPoAQab+6F+0wXSRXFLQbk4aOmt8XWWhpIkPDmIWdMgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=OQ/Hvd7l; arc=none smtp.client-ip=209.85.161.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5a0269b0537so205713eaf.0 for ; Thu, 22 Feb 2024 01:40:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708594842; x=1709199642; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Mzp7gOUhADSPQHe9BbGbbZnz24qrFAsUkCIt0RA8CU=; b=OQ/Hvd7ljcbfo4JzytYMqCSjMifsUiCanXJBxAx3RUvHCW6m9Cb21beTQmWbiRQCnw PlbiMM3YsHW3d45h/huZ756KuTiZwtH3YMpMDINdqoIXnb+BPeXALCIUuZr75g/4fLT6 bDlj4J1KDL1HFN5mgrYBJ7xXT9abGjj/yZgDcZIw7eSjtGi21TsYwxKTziLWpuru/FMI aXf5OQBoJTixritfqIVrQlzIaciWwj/MU5iLtokgtWzE0aoUeAOH1qR6pkzDZV232Fan ln8NzU7IGl5rUnLx6EeIUPm5+kE4RQn2xKZRQe/EkjeEEl/StW8TzExBsEVrY9wv722H 8JOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708594842; x=1709199642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Mzp7gOUhADSPQHe9BbGbbZnz24qrFAsUkCIt0RA8CU=; b=dTgXqRkApXfpnKByWT2AJxLYvZ0D20zfENLOT6W0ivCsGtKpKbScs6N6ClquT6lJTz D+lRcXnuXr+OMXN62O4Dk7fihZ09OBNvS3yKrvs7wYbEw3QiNd8EMFxivti84NM7HDXn 8yBCd/QMxkfETJGU2H3cykrkM17UrAJGxUZEcRyG9MKRjGApLWsMsZjbNkIcFXVjALaV bFpz0zjetjb5IE+A6nj7H+VB8w/yJGdrqfP5LY0dnJ0SToiy1mrrj8LgjcDKlf786oEs bq8QlQ7C5jSzi8sVj7YPm4wV2rrtSaER+e4PMyJL1cLWq5xZU1EWifGMzun68/c1/dkT EQzQ== X-Forwarded-Encrypted: i=1; AJvYcCVsEYGYWhd0M+sim90R8Yv35YQgCsnW5nn+vMImhBszU2zrah0yy9kj2VRyyZTXtTFa07xi10ohjMpokbRCZvFJqQi+V5J2s9mKjPHU X-Gm-Message-State: AOJu0YyzBxwpsP5nqVwsOvsj7uSweyRNShwrKARkwpfinG1ofrIk6z1c Uq9kJiPl6fKEO42xUNDA+NrUYcc599IDv7kU7ZI64qbeEthu3c+GGAwHoL10pJ0P9dmceK4S9Ux cafc= X-Received: by 2002:a05:6871:4e43:b0:21e:9dbd:ce3b with SMTP id uj3-20020a0568714e4300b0021e9dbdce3bmr938781oab.6.1708594842413; Thu, 22 Feb 2024 01:40:42 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n15-20020a05680803af00b003c17c2b8d09sm130699oie.31.2024.02.22.01.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:40:42 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Cc: Marc Zyngier , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Atish Patra , Andrew Jones , Sunil V L , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel Subject: [PATCH v14 03/18] irqchip/sifive-plic: Use devm_xyz() for managed allocation Date: Thu, 22 Feb 2024 15:09:51 +0530 Message-Id: <20240222094006.1030709-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222094006.1030709-1-apatel@ventanamicro.com> References: <20240222094006.1030709-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791592188583812327 X-GMAIL-MSGID: 1791592188583812327 Use devm_xyz() for allocations and mappings managed by the Linux device driver framework. Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 49 ++++++++++--------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 3d7a61c35572..558ae63795d9 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -435,39 +435,30 @@ static int plic_probe(struct platform_device *pdev) plic_quirks = (unsigned long)id->data; } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; priv->dev = dev; priv->plic_quirks = plic_quirks; - priv->regs = of_iomap(to_of_node(dev->fwnode), 0); - if (WARN_ON(!priv->regs)) { - error = -EIO; - goto out_free_priv; - } + priv->regs = devm_platform_ioremap_resource(pdev, 0); + if (WARN_ON(!priv->regs)) + return -EIO; - error = -EINVAL; of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", &nr_irqs); if (WARN_ON(!nr_irqs)) - goto out_iounmap; + return -EINVAL; priv->nr_irqs = nr_irqs; - priv->prio_save = bitmap_alloc(nr_irqs, GFP_KERNEL); + priv->prio_save = devm_bitmap_zalloc(dev, nr_irqs, GFP_KERNEL); if (!priv->prio_save) - goto out_free_priority_reg; + return -ENOMEM; nr_contexts = of_irq_count(to_of_node(dev->fwnode)); if (WARN_ON(!nr_contexts)) - goto out_free_priority_reg; - - error = -ENOMEM; - priv->irqdomain = irq_domain_add_linear(to_of_node(dev->fwnode), nr_irqs + 1, - &plic_irqdomain_ops, priv); - if (WARN_ON(!priv->irqdomain)) - goto out_free_priority_reg; + return -EINVAL; for (i = 0; i < nr_contexts; i++) { struct of_phandle_args parent; @@ -538,10 +529,10 @@ static int plic_probe(struct platform_device *pdev) i * CONTEXT_ENABLE_SIZE; handler->priv = priv; - handler->enable_save = kcalloc(DIV_ROUND_UP(nr_irqs, 32), - sizeof(*handler->enable_save), GFP_KERNEL); + handler->enable_save = devm_kcalloc(dev, DIV_ROUND_UP(nr_irqs, 32), + sizeof(*handler->enable_save), GFP_KERNEL); if (!handler->enable_save) - goto out_free_enable_reg; + return -ENOMEM; done: for (hwirq = 1; hwirq <= nr_irqs; hwirq++) { plic_toggle(handler, hwirq, 0); @@ -551,6 +542,11 @@ static int plic_probe(struct platform_device *pdev) nr_handlers++; } + priv->irqdomain = irq_domain_add_linear(to_of_node(dev->fwnode), nr_irqs + 1, + &plic_irqdomain_ops, priv); + if (WARN_ON(!priv->irqdomain)) + return -ENOMEM; + /* * We can have multiple PLIC instances so setup cpuhp state * and register syscore operations only once after context @@ -577,19 +573,6 @@ static int plic_probe(struct platform_device *pdev) dev_info(dev, "mapped %d interrupts with %d handlers for %d contexts.\n", nr_irqs, nr_handlers, nr_contexts); return 0; - -out_free_enable_reg: - for_each_cpu(cpu, cpu_present_mask) { - handler = per_cpu_ptr(&plic_handlers, cpu); - kfree(handler->enable_save); - } -out_free_priority_reg: - kfree(priv->prio_save); -out_iounmap: - iounmap(priv->regs); -out_free_priv: - kfree(priv); - return error; } static struct platform_driver plic_driver = {