Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp492606pxy; Fri, 30 Apr 2021 09:35:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiMSIV9zTbd/pwsQM+Tu/u77IARoARbu9zybsQvJ7oRE8WnQgmU0Zggh+aFuJnvIoJyPNB X-Received: by 2002:a17:90a:6b05:: with SMTP id v5mr4200172pjj.70.1619800502010; Fri, 30 Apr 2021 09:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619800502; cv=none; d=google.com; s=arc-20160816; b=oMA/KNZoVEHFuxb69Bu/wARoKKpnyeYvMEAaszwafdIbRSr69X2R34lkI3zR0YUMtv ZI00Lw7otvNDfZUOV8umIKWRvzbo4V53ob3gXCSWadJK8FkX2hba+xsEOKZ0sHPxa1Io SKcgXYEChrbIMvsJfPJaOWaDpbw7Vq5VsM8TmVPWbeaptGZCEE9+p4rDfDHqfxMf5Xj+ IllMgpWBB3o3xEsYLmMhQuP6iGlXva9ReYIEOCuIIRyxP6Lo7h8KBp0GJdmQw56trTtd 31Uy81xAwwOhZ/JsAiWh/Z/knVZS2w3nZo3tucH6LU2FVwuFfRqjvQLrhDdlu8zfGwx8 Sqhw== 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=ESpGLqTieS5UXmEO/XNUp3gEyxnNH6VUP8Tvy1t7C7WESXE4uknCcg1gDPJnnTb8Tq 7eo7fk7EpFTnSJ3O0EIhrYXbdvWZOR/sAZhOHUp8nhfuCBTGNveTi9lBvQSlXzBeq+sa oWY0VPZ+MX3aCXWq+2xbn+dcg9mkLdM/3S6czaAHyDmKMCTWg8Ki8pjKtBTW4qwVJ1Mv fW7AIZXG3syn6wTMu0KkpA/X9wFrq5xqaWsfox2bOIXU7qemlP/ywmd15ELsyE6qqcZl IvWR6g6hef/fH7zuRUtIq0VH8eSB5LUHytf/IGK+LzQMY6LZTzkZ2NrhA1IFzBnY7GDO Mdng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dFmKF6iX; 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 s20si2604074pfm.262.2021.04.30.09.34.49; Fri, 30 Apr 2021 09:35:01 -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=dFmKF6iX; 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 S231260AbhD3QdQ (ORCPT + 99 others); Fri, 30 Apr 2021 12:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbhD3QdH (ORCPT ); Fri, 30 Apr 2021 12:33:07 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39F5C06174A for ; Fri, 30 Apr 2021 09:32:18 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id d19so35560259qkk.12 for ; Fri, 30 Apr 2021 09:32: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=dFmKF6iXF2mQCRnP54zm7GWbK0lGHM/hmMC7TC5NfCtp21mDffveeqjWcD+DSarBRo wdFbDwRcVptoaa4QWgI4KrbrPykHMd/9hILqAMKfpBffJjG5b4ADyEwrHR6HNS1l6CVs CYi53eO8rzy+MH0X2496H1DtenKtuFZYppmNmfkn+HtzQCAhS+Mg0gBAM0zDsHRniQxS mAGvHaapfa8dMldGTdqU1SNJ6Dc8U4j7vKh1sx6bvBkLs8cO2hJ0ndMZWHequb1VVSfz GVBff90c3LXegAbNsh8HFaugM5FLh4ky+1760qRtY1DSi+7GW210Bo7b6TWErD3KWkxo cFNw== 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=Dq78s807/5O5vFun4czl4++EZloNTXGMoNMo3X49pj5uFTaJizxFQx62Z7wNSVVqxQ dDQTMzCDkGPXjGQWqiolYcKkA7V/kAW+aHLKNxwvjqsy27kFDNjRDNyk+ndjrmkv2iFb hspM1s36DMCwobLHzUJ42d192iN0qgebdcU/1EbsB9b7wZ20A2BGGZZzJ1HCktslXbfs Hs8SpM2agKA9Yztr601mqKsuPiqSnMAndXv2hHliQLwJR7kd1j5JvSbJQ9GG8eHTbvsw MfZOqBS6fmm3/CPNPlI/E54rL2LWTKpNN8nEOxHseBZgO6qPiykxM0WK3KbGTn7ZDPDT P/ZQ== X-Gm-Message-State: AOAM532lOOs1oIqZSq5IGLDpYctUSCrqhOYKhYNANuzqDdb0ZzX4SZnn Ry+l/06a9zxaumPaE+CKehs= X-Received: by 2002:a37:e50e:: with SMTP id e14mr6122866qkg.117.1619800338210; Fri, 30 Apr 2021 09:32:18 -0700 (PDT) Received: from li-908e0a4c-2250-11b2-a85c-f027e903211b.ibm.com.com ([2804:14c:482:7b04::1001]) by smtp.gmail.com with ESMTPSA id p1sm2624334qtu.89.2021.04.30.09.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 09:32:17 -0700 (PDT) From: Leonardo Bras To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Joel Stanley , Christophe Leroy , Leonardo Bras , Alexey Kardashevskiy , Nicolin Chen , Niklas Schnelle Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 04/11] powerpc/pseries/iommu: Add ddw_list_new_entry() helper Date: Fri, 30 Apr 2021 13:31:39 -0300 Message-Id: <20210430163145.146984-5-leobras.c@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210430163145.146984-1-leobras.c@gmail.com> References: <20210430163145.146984-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