Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1123153pxf; Fri, 9 Apr 2021 00:02:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoOI9yHBvqEXqsMvbaWNiJ88sGwoe37riTLCU4AJGg+BGQEjPTQDZFmD57tiweO6Zq7rz7 X-Received: by 2002:a17:906:f953:: with SMTP id ld19mr14295069ejb.164.1617951777745; Fri, 09 Apr 2021 00:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617951777; cv=none; d=google.com; s=arc-20160816; b=bSe7u0rKJpLfV7wlDKMbkDIt6G/Z1CXxlBhYDBt+Qz8GzzObeKRx7BxSwv6yb65nqF m146CszQ/wsfauguDorO3tj2+CUsoC3Znfm/xuTngg4auzHmDbPKGzX+SEvJkEY0zJ/V DXakEvAcbNdGUG04+kn/+ZAkb3d10CYSFSN22Dc4lCEaSLAZ1NSd5DIU3tVEckLnhiBh 5vDXV7nmEuaNu3pDvUKD1GV6GOsXK7uwtnciVhqFo7JU4p+xoCDZd4SvUfKGYbGLTXE4 saQ3DJHZyc1tvMycjL/TL781MtiiSsuOLyf47g5XyusQXxpGufCUnEFLb2EK+G8PlIOk cR2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+JLpB4B4pZBi2h8DfTURJ08nGqgdO/pYNV0sF8isNXA=; b=ZbckhoVgPcO+em87rWtZCVzUu17zLNSrxOWsoTVER44t7WSRM4W3dgUSKE/bHTN61y //lx9lI0BE+NWa6F3nvs2KB5Vho+y7vIuKL2APWrhWyriseuGrK6XQgPf7l97fXollR/ tc5AtNB1hEvRtfpsPgW8ZTT3tIsgGrufVxkLLgWAyGOSYPZu68tfd0SsTkP7tLbcm981 23y4BNNZqpXQznpY0Jt7YtDQRCDn7rggLazSVr2MknDRgP1/toTQHetwGaAha75UCJof BY9PK0xofrF1q/7KURdv4+AWD5BT5Dq6p0uobrRChEbfJGhnuFzhPzLlRX3I+mrIKpnD gKkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bewilderbeest.net header.s=thorn header.b=CidT4DYv; 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=NONE dis=NONE) header.from=bewilderbeest.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f21si1438095edy.337.2021.04.09.00.02.34; Fri, 09 Apr 2021 00:02: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=@bewilderbeest.net header.s=thorn header.b=CidT4DYv; 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=NONE dis=NONE) header.from=bewilderbeest.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233507AbhDIHBT (ORCPT + 99 others); Fri, 9 Apr 2021 03:01:19 -0400 Received: from thorn.bewilderbeest.net ([71.19.156.171]:45231 "EHLO thorn.bewilderbeest.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233333AbhDIHBT (ORCPT ); Fri, 9 Apr 2021 03:01:19 -0400 Received: from hatter.bewilderbeest.net (unknown [IPv6:2600:6c44:7f:ba20::7c6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 240CB86; Fri, 9 Apr 2021 00:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1617951666; bh=+JLpB4B4pZBi2h8DfTURJ08nGqgdO/pYNV0sF8isNXA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CidT4DYvw7ZKpQkK8gdGXnDdEJXCD9goWMGofn7kROmWmdqG5EWltzowMmaLMHNGU 6M7G/SO7aMkIYPy7bEV3EaXiUUNr3sIQU3g/L8T8wnqwdiGHfBq5p8sFg0zAprzD90 FGNpAD/S63WbHASqkhrS6RDPjVQU9ap1qxx8FeqA= Date: Fri, 9 Apr 2021 02:01:04 -0500 From: Zev Weiss To: Andrew Jeffery Cc: Joel Stanley , openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: Re: [PATCH v5 2/4] drivers/tty/serial/8250: refactor sirq and lpc address setting code Message-ID: References: <20210408011637.5361-1-zev@bewilderbeest.net> <20210408011637.5361-3-zev@bewilderbeest.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 09, 2021 at 12:06:16AM CDT, Andrew Jeffery wrote: > > >On Thu, 8 Apr 2021, at 10:46, Zev Weiss wrote: >> This splits dedicated aspeed_vuart_set_{sirq,lpc_address}() functions >> out of the sysfs store functions in preparation for adding DT >> properties that will be poking the same registers. While we're at it, >> these functions now provide some basic bounds-checking on their >> arguments. >> >> Signed-off-by: Zev Weiss >> --- >> drivers/tty/serial/8250/8250_aspeed_vuart.c | 51 ++++++++++++++------- >> 1 file changed, 35 insertions(+), 16 deletions(-) >> >> diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c >> b/drivers/tty/serial/8250/8250_aspeed_vuart.c >> index c33e02cbde93..8433f8dbb186 100644 >> --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c >> +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c >> @@ -72,22 +72,31 @@ static ssize_t lpc_address_show(struct device *dev, >> return snprintf(buf, PAGE_SIZE - 1, "0x%x\n", addr); >> } >> >> +static int aspeed_vuart_set_lpc_address(struct aspeed_vuart *vuart, u32 addr) >> +{ >> + if (addr > U16_MAX) >> + return -EINVAL; >> + >> + writeb(addr >> 8, vuart->regs + ASPEED_VUART_ADDRH); >> + writeb(addr >> 0, vuart->regs + ASPEED_VUART_ADDRL); >> + >> + return 0; >> +} >> + >> static ssize_t lpc_address_store(struct device *dev, >> struct device_attribute *attr, >> const char *buf, size_t count) >> { >> struct aspeed_vuart *vuart = dev_get_drvdata(dev); >> - unsigned long val; >> + u32 val; >> int err; >> >> - err = kstrtoul(buf, 0, &val); >> + err = kstrtou32(buf, 0, &val); >> if (err) >> return err; >> >> - writeb(val >> 8, vuart->regs + ASPEED_VUART_ADDRH); >> - writeb(val >> 0, vuart->regs + ASPEED_VUART_ADDRL); >> - >> - return count; >> + err = aspeed_vuart_set_lpc_address(vuart, val); >> + return err ? : count; >> } >> >> static DEVICE_ATTR_RW(lpc_address); >> @@ -105,27 +114,37 @@ static ssize_t sirq_show(struct device *dev, >> return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg); >> } >> >> +static int aspeed_vuart_set_sirq(struct aspeed_vuart *vuart, u32 sirq) >> +{ >> + u8 reg; >> + >> + if (sirq > (ASPEED_VUART_GCRB_HOST_SIRQ_MASK >> ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT)) >> + return -EINVAL; >> + >> + sirq <<= ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT; >> + sirq &= ASPEED_VUART_GCRB_HOST_SIRQ_MASK; > >This might be less verbose if we reordered things a little: > >``` >sirq <<= ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT; >if (sirq & ASPEED_VUART_GCRB_HOST_SIRQ_MASK) > return -EINVAL; >sirq &= ASPEED_VUART_GCRB_HOST_SIRQ_MASK; >``` Hmm, that (or something similar, perhaps with a '~' on the mask in the if condition?) does seem like it'd be a nice improvement, though I suppose it'd also mean we'd fail to reject some way-out-of-range sirq values (e.g. if it had its MSB set) -- so I think I'll leave it as is, just in the name of thoroughness/paranoia? > >But otherwise it looks okay, so > >Reviewed-by: Andrew Jeffery > Thanks.