Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1182325pxb; Fri, 21 Jan 2022 11:39:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlZYNp/yNR/gImGWLk7MOiHbo4PIEmMGzHhhTlCO1n4t9uks4+EAzzZy0Ry0KD3K24wBO1 X-Received: by 2002:a63:83c1:: with SMTP id h184mr3897992pge.325.1642793995446; Fri, 21 Jan 2022 11:39:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642793995; cv=none; d=google.com; s=arc-20160816; b=XeudHm7o20YEJXq2eDbwHX/v9dZcb+vZVDodwogjHrYoZki2JkHLTVr9wABqw+ELTy y4mG817Jd7pvdPQFYqlJKmqkoUepqoKb5VeDYtF86UgM/dzU9r6L/fxYaMsqtY7u1Cz0 e+Gr7ShUM4uTqKIEdRsA4aDLw6ttovpfz8XMdTKDGnsgdFmx2MnGBl9/SXMrR5rCenra QGBT1zoZxZJ8yGTt3y4EDpzx9kH8JjY/r7FLcimr5mimCaoJer8W2G9Z68wjgpQUxmzg 0Z7JtmcfO+b+hMNnF/lfE+MdZBzDpHelnP+PAV4tTgu0+zeU+C9MN2H8WJ0ykMJXjDPF lrrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:sender:dkim-signature; bh=LnWfVRfNsWhn3KCKfkXN1IPDGRcjwiXW3hktOQD1t2c=; b=A6jMFMLK3Q18NwWjVJRFvTeMkVHA97epbNsOHIJxo/c7xQ0npoErBU6srb0W9XOj2Y CnJYEAIDvEVw+7EVeZLfe3+e4koJOFFFVKYKucY5GuMVyImAJl70m13bj6sBs620eE8H FEJa0FvnTfw0LJGkzgQ1zcW8iDkNRKVfUqL3QHs1OlHT7WZg+6W7vYzwpUYsEt/L7frO gzHdziWprDFzkGthOFNMqUgj6JLaOipna79IGHgU6czhM/OXNaxYnVL7IKV4716kFzeF 5LUucfp8PewL86Mkef7yxTLX1QbNVlXxcRgP8BazQdIsup9RwETR4EcUExRk4D8iO6o+ 4jMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DGdvkYeV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bm18si217764pgb.109.2022.01.21.11.39.40; Fri, 21 Jan 2022 11:39:55 -0800 (PST) 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=20210112 header.b=DGdvkYeV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355899AbiASPrD (ORCPT + 99 others); Wed, 19 Jan 2022 10:47:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355624AbiASPq4 (ORCPT ); Wed, 19 Jan 2022 10:46:56 -0500 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CF5FC061574; Wed, 19 Jan 2022 07:46:56 -0800 (PST) Received: by mail-oi1-x229.google.com with SMTP id e81so4745381oia.6; Wed, 19 Jan 2022 07:46:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:to:cc:references:from:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=LnWfVRfNsWhn3KCKfkXN1IPDGRcjwiXW3hktOQD1t2c=; b=DGdvkYeVNv4oLdoNZFXAcIQrBVGwi1LW0pO1aw1PUyTMzM/x7RTnx9WbMElqfYkHto 9A+m+qNAwb5h8eJZfNU+JiOHzqvJ3Gx8nAt4bpnF5R/SjSigbffSUynmoeU/jZh0/V4e NiemJVFd61ZMqGiuPPGIIWv6aiqWZ4WLlXzOodhtuJeFs5FkxTzDtfso80ILD04zJdQu ZwMfoTVzzrvn1GWuYHG653iJH0nO/a9Wby1LPNYTrD4JK/FdgBfBt/n6egVPpSmvoFNm UFunnqgnDVno/mjWEYf90clfQ4sa0IjicYcXmy9WbpycDOUv6t9sILI+Y+D5PUeFGJtn NMXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:to:cc:references:from:subject:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=LnWfVRfNsWhn3KCKfkXN1IPDGRcjwiXW3hktOQD1t2c=; b=faUHeNZA/+e8W42mB0OnP9SdsDz8dGxD16BhHxpskv3nsTwTvBaYnncSPwJp4+2LqT dYcGqas8eLFcbDtP+FAwoonAMv6c1DhfHOs5RoFbmmtyS6h1s48XJ2Dr7ADMrN6Tpkr1 OV0tU7Khox6FMw1Zy3VP3an9v5ghE08qQ3agPT/amYT8LZIwoVrXfFYitSxQFeBswOp3 3CnOfRKF+WjwilMaWvwDff2TXpEL9CaoOR42eRtQAOkSrmJXquCOfF9cL6DXj3C04PoN wLrJFuhWDBkMkOgKht2Ddg1ThADMHfxpWPVwUF93BhFttXwoFcKni13JuyVEIBkrfYN3 oYjQ== X-Gm-Message-State: AOAM532M9VNtMy40Vl4bfJbJUWJJ2fBhXGyVrm9kz4mmzvC9kBp3plM0 sd5h7K0bLSnjTj2xRlsFZjU= X-Received: by 2002:a05:6808:f13:: with SMTP id m19mr3513973oiw.123.1642607215838; Wed, 19 Jan 2022 07:46:55 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id e1sm75857oou.0.2022.01.19.07.46.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Jan 2022 07:46:54 -0800 (PST) Sender: Guenter Roeck To: Andy Shevchenko , Terry Bowman Cc: linux-watchdog@vger.kernel.org, Jean Delvare , linux-i2c , Wolfram Sang , "Rafael J. Wysocki" , Linux Kernel Mailing List , Wim Van Sebroeck , Robert Richter , Tom Lendacky , "Shah, Nehal-bakulchandra" , Basavaraj Natikar , Shyam Sundar S K , Mario Limonciello References: <20220118202234.410555-1-terry.bowman@amd.com> <20220118202234.410555-3-terry.bowman@amd.com> From: Guenter Roeck Subject: Re: [PATCH v3 2/4] Watchdog: sp5100_tco: Refactor MMIO base address initialization Message-ID: Date: Wed, 19 Jan 2022 07:46:52 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/19/22 3:53 AM, Andy Shevchenko wrote: > On Tue, Jan 18, 2022 at 10:23 PM Terry Bowman wrote: >> >> Combine MMIO base address and alternate base address detection. Combine >> based on layout type. This will simplify the function by eliminating >> a switch case. >> >> Move existing request/release code into functions. This currently only >> supports port I/O request/release. The move into a separate function >> will make it ready for adding MMIO region support. > > ... > >> To: Guenter Roeck >> To: linux-watchdog@vger.kernel.org >> To: Jean Delvare >> To: linux-i2c@vger.kernel.org >> To: Wolfram Sang >> To: Andy Shevchenko >> To: Rafael J. Wysocki >> Cc: linux-kernel@vger.kernel.org >> Cc: Wim Van Sebroeck >> Cc: Robert Richter >> Cc: Thomas Lendacky > > Same comment to all your patches. > > ... > >> +static int __sp5100_tco_prepare_base(struct sp5100_tco *tco, >> + u32 mmio_addr, >> + const char *dev_name) >> +{ >> + struct device *dev = tco->wdd.parent; > >> + int ret = 0; > > Not really used variable. > >> + if (!mmio_addr) >> + return -ENOMEM; >> + >> + if (!devm_request_mem_region(dev, mmio_addr, >> + SP5100_WDT_MEM_MAP_SIZE, >> + dev_name)) { >> + dev_dbg(dev, "MMIO address 0x%08x already in use\n", >> + mmio_addr); >> + return -EBUSY; >> + } >> + >> + tco->tcobase = devm_ioremap(dev, mmio_addr, >> + SP5100_WDT_MEM_MAP_SIZE); Talking about line splits, is this one necessary ? >> + if (!tco->tcobase) { >> + dev_dbg(dev, "MMIO address 0x%08x failed mapping.\n", >> + mmio_addr); > >> + devm_release_mem_region(dev, mmio_addr, >> + SP5100_WDT_MEM_MAP_SIZE); > > Why? If it's a short live mapping, do not use devm. > This is not short lived; it is needed by the driver. The release is an artifact of calling this function twice and ignoring the error from devm_ioremap() if the first call fails. devm_release_mem_region() isn't strictly needed but that would result in keeping the memory region reserved even though it isn't used by the driver. There is a functional difference to the original code, though. The failing devm_ioremap() causes the code to try the alternate address. I am not sure if that really adds value; devm_ioremap() fails because the system is out of virtual memory, and calling it again on a different address doesn't seem to add much value. I preferred the original code, which would only call devm_ioremap() after successfully reserving a memory region. >> + return -ENOMEM; >> + } > >> + dev_info(dev, "Using 0x%08x for watchdog MMIO address\n", >> + mmio_addr); > > Unneeded noise. > >> + return ret; > > On top of above it's a NIH devm_ioremap_resource(). > Not sure what NIH means, but if you refer to the lack of devm_release_mem_region(), again, it isn't short lived. >> +} > > > ... > >> + int ret = 0; > > Redundant assignment. > > ... > >> + /* Check MMIO address conflict */ >> + ret = __sp5100_tco_prepare_base(tco, mmio_addr, dev_name); > >> + >> + /* Check alternate MMIO address conflict */ > > Unify this with the previous comment. > Why ? It refers to the code below. If that is a single or two comments is really just POV. >> + if (ret) >> + ret = __sp5100_tco_prepare_base(tco, alt_mmio_addr, >> + dev_name); > > ... > >> + if (alt_mmio_addr & ((SB800_ACPI_MMIO_DECODE_EN | >> + SB800_ACPI_MMIO_SEL) != >> + SB800_ACPI_MMIO_DECODE_EN)) { > > The split looks ugly. Consider to use temporary variables or somehow > rearrange the condition that it doesn't break in the middle of the one > logical token. Split at the &, maybe. > >> + alt_mmio_addr &= ~0xFFF; > > Why capital letters? > >> + alt_mmio_addr += SB800_PM_WDT_MMIO_OFFSET; >> + } > > ... > >> + if (!(alt_mmio_addr & (((SB800_ACPI_MMIO_DECODE_EN | >> + SB800_ACPI_MMIO_SEL)) != >> + SB800_ACPI_MMIO_DECODE_EN))) { > > Ditto. > >> + alt_mmio_addr &= ~0xFFF; > > Ditto. > >> + alt_mmio_addr += SB800_PM_WDT_MMIO_OFFSET; > > ... > > Okay, I see this is the original code like this... Perhaps it makes > sense to reshuffle them (indentation-wise) at the same time and > mention this in the changelog. > > ... > >> release_region(SP5100_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); > > Is it still needed? I have no context to say if devm_iomap() and this > are not colliding, please double check the correctness. > Not sure I understand. This is the release of the io region reserved with request_muxed_region() at the beginning of this function. Why would it no longer be necessary to release that region ? Guenter