Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp224467pxy; Thu, 22 Apr 2021 00:09:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1vweGZv1Ilcj77RPSV7uFeBQPMCfobYR9aek5N7w2QJ4yO3aBiKmvPPbZSu4ODMj5SQ4P X-Received: by 2002:a17:907:264f:: with SMTP id ar15mr1866345ejc.484.1619075397728; Thu, 22 Apr 2021 00:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619075397; cv=none; d=google.com; s=arc-20160816; b=lMUUnJHMvJ9jLYdrzxbqiPXCZEbNZX37LrEs14wGFyinvDbv1fFE9c/YBz1TLbTdJY DfBIq53npOTQuTkBrJAAkdAtInNAQcXne4ASWqsI67uLSvPX89dPYLj0Oe+ANnFiFBwZ PC9Rzhcw7TbhPQdhTMTKTy53q9LfZAspDYWpdF4rAegRVjhkwYrwL6larTTO5cHLqsbl DBGvjn+ua/zcPKbOeA+FoJKSXMVwtLks/P1cTTTQHWOqc8SbaOZKW/VjLAJqN0rUhUEv np5VXEVOabzhgcziA4bjNI9qwafD3ZkMXQzpI64h0cOlIe2OyttjMJRL1iRu5exJrhEP ejug== 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=ijXkh5bc5eEQEAPTsHyC4GzIBhozaiyqx/uWR9aUj2Q=; b=yfCpv+f+ki+M/KXkRnSI9mOeBBO28q2LS+DmAX/XCkmVqlb+vyTI0npHUWd04Tw0wx HnYnFBMNW0hV25ifujVF9kniQ31AC3BtGKWbaZfuZkDAA9j/pIKiUyoCuAC3Ej1WSxXU xbgNMaxiBttKAc4T/vDldYP+qn4B0HHimg4D7yR5oRWk7Qda2bnSmO+780ciLHbF6whF oeKXgxjMD34H7z62tSAuYoZWKlTxQAy7e8fuC4hCRNbcwOhDAGpDwUY9+PGgADizHtXs FVY3WTc+K0bfv5cV6oVuMPBBHJ7o4Z99scz687c7r8GPd91GifnctWI93v9pdgJw8leX jTrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jUULwv6s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id bh18si1468403ejb.405.2021.04.22.00.09.34; Thu, 22 Apr 2021 00:09:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jUULwv6s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S235034AbhDVHJI (ORCPT + 99 others); Thu, 22 Apr 2021 03:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235065AbhDVHI6 (ORCPT ); Thu, 22 Apr 2021 03:08:58 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F731C06138D for ; Thu, 22 Apr 2021 00:08:18 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id f12so33110993qtf.2 for ; Thu, 22 Apr 2021 00:08:18 -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 :mime-version:content-transfer-encoding; bh=ijXkh5bc5eEQEAPTsHyC4GzIBhozaiyqx/uWR9aUj2Q=; b=jUULwv6sWz6Zkys3P6Wn8srjX65o/R+FGjJ9gVnAxHajP75zVpsQlVdJ5ys7H4fIsV viroDkq72TSmyHBFpoV6WN9jxo3FTP7C6hl1Mo9U/X3QBhndnbM1d+WE0JorWTB2WE13 zWLK4BsXcQTdKw2FC9zw1hPtjjp61IAYVf6LbXR1JV2coNHb9XFZrkkvPjjAZ/9dq3hU ZXN/2cdiCwrYKACSQ0KnwMMmPCxGz5IwRQpeOfXBbJnjQNqetVqyf3cpk3s3CnnO8RZc wKdQJPISZ6Ht21rEBVmm9D51Kx8eA/wTPsPrdH8GFQImawz0EanM/yu9hrb/IMFEMEYq DUVQ== 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:mime-version:content-transfer-encoding; bh=ijXkh5bc5eEQEAPTsHyC4GzIBhozaiyqx/uWR9aUj2Q=; b=sA11etnEz9TOBib2yJBtkv4dSSUKh64CtOU5rrml/EFjm7YoJKa76B8ImgIePLI9Xs kwpVJxanUzEz2X/7Wp466g/7zg2TCWE/qmYdza7C4WNPMe68pTe6phQuy2MqocjK99EM VmLCFD2Blb5+bf0KBO1ATsKgEzvM7Y01AetmFvk9zT9zr4DUD1x4MODCpNdYRkv45yLM nhFVf1oDWZyHsDIvJ6ImIYyH1S4DW1BGD0PZ6rN830KrkTSBwDpJfU/eDHKXZwOp3Jfv J1e+fp4Y/5IDkfbU9fosLq9LZL8YmbqRpl/5cZKGBw5k5EGXTBJWToxxDqJK7a3wfwTa ZpSQ== X-Gm-Message-State: AOAM532bC6lHu6B3NVHgYEDKWZqEkD3lHoBjbBEuamCYFysSS0Ufori/ +ng/HQv29Y/BtHK2cgr3MUU= X-Received: by 2002:ac8:5a0b:: with SMTP id n11mr1721655qta.381.1619075297815; Thu, 22 Apr 2021 00:08:17 -0700 (PDT) Received: from li-908e0a4c-2250-11b2-a85c-f027e903211b.ibm.com.com ([177.35.200.187]) by smtp.gmail.com with ESMTPSA id w67sm1658329qkc.79.2021.04.22.00.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 00:08:17 -0700 (PDT) From: Leonardo Bras To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Leonardo Bras , Joel Stanley , Christophe Leroy , Alexey Kardashevskiy , Nicolin Chen , Niklas Schnelle Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/11] powerpc/pseries/iommu: Add ddw_list_new_entry() helper Date: Thu, 22 Apr 2021 04:07:16 -0300 Message-Id: <20210422070721.463912-5-leobras.c@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210422070721.463912-1-leobras.c@gmail.com> References: <20210422070721.463912-1-leobras.c@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two functions creating direct_window_list entries in a similar way, so create a ddw_list_new_entry() to avoid duplicity and simplify those functions. Signed-off-by: Leonardo Bras Reviewed-by: Alexey Kardashevskiy --- arch/powerpc/platforms/pseries/iommu.c | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index d02359ca1f9f..6f14894d2d04 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -870,6 +870,21 @@ static u64 find_existing_ddw(struct device_node *pdn, int *window_shift) return dma_addr; } +static struct direct_window *ddw_list_new_entry(struct device_node *pdn, + const struct dynamic_dma_window_prop *dma64) +{ + struct direct_window *window; + + window = kzalloc(sizeof(*window), GFP_KERNEL); + if (!window) + return NULL; + + window->device = pdn; + window->prop = dma64; + + return window; +} + static int find_existing_ddw_windows(void) { int len; @@ -882,18 +897,15 @@ static int find_existing_ddw_windows(void) for_each_node_with_property(pdn, DIRECT64_PROPNAME) { direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len); - if (!direct64) - continue; - - window = kzalloc(sizeof(*window), GFP_KERNEL); - if (!window || len < sizeof(struct dynamic_dma_window_prop)) { - kfree(window); + if (!direct64 || len < sizeof(*direct64)) { remove_ddw(pdn, true); continue; } - window->device = pdn; - window->prop = direct64; + window = ddw_list_new_entry(pdn, direct64); + if (!window) + break; + spin_lock(&direct_window_list_lock); list_add(&window->list, &direct_window_list); spin_unlock(&direct_window_list_lock); @@ -1303,7 +1315,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %pOF\n", create.liobn, dn); - window = kzalloc(sizeof(*window), GFP_KERNEL); + window = ddw_list_new_entry(pdn, ddwprop); if (!window) goto out_clear_window; @@ -1322,8 +1334,6 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) goto out_free_window; } - window->device = pdn; - window->prop = ddwprop; spin_lock(&direct_window_list_lock); list_add(&window->list, &direct_window_list); spin_unlock(&direct_window_list_lock); -- 2.30.2