Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1133537imp; Thu, 21 Feb 2019 19:47:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IYL0ZVoH8XYYz11nOsMivaglvDPZGRaCIL9bl6DgIHwWtf4NuacVd/7pip9maL1Vv5jc9Fs X-Received: by 2002:a63:1616:: with SMTP id w22mr1926510pgl.200.1550807273822; Thu, 21 Feb 2019 19:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550807273; cv=none; d=google.com; s=arc-20160816; b=U2T7jRPsynLxTvOK928d/BGr/mrAZUaEAlBbIs1D37Sin668KVh70uTxXTtGYlfhx9 p25s759sI56zvfzMNRvniWX2I/5N4ndxc+LRPv8XLhPODN3cdHIGztLcnNE4X3w2vKJM LtJartNIaSKazfkHFILu0lOuTfWgi8dnkTpeBrBBIxPLnhof0tLXPM9qmgnXKf5EU0ai djfSzgqG8zTrdikBgVS8hL2NvG/T+npezN3a8mk1+ysovwVHI4P1PvOnwCQzm+bgmNrv ff+WblZv/SweTJI1khecwHRq7wqboPpuzmcFH609Z5yhhe5qnnX1TpS5BSNu/gHheAEE lyvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Sk41UeLkzzTn4KypRu0CQVd69ZDRQ+8bC0EFmE/pbHI=; b=EySnF4fhbAW15L9W6PkYXf6Y8Kphr/JE0o8f3o2e4VtQKSI77uTC1/rFxF1YtGXTlo 6whfK8guufm/O0Uj3gNnaNhlUMuJcihEO7bkgk38y5v/oUwF4NTpzHBow0mwvY6KShw5 dkOEph3YBEIbCZBynAzVKPLnOgfrSFBsZ0UUVTtidxc8QrGyRRVfFlNNIOmyjoXV5J8L vf13aWiWA68qehJdkHAx/HFmCKAlrNTdL7hjzE9wZOC5TiqZUHfAM05QY9I/ZCOUSMhd AVP/jeB9z2p0ZEFuE/iCHx21GGUra4fO9jrVInjX17bPm6nP7V9fzQKDGBfHL0xosdL5 jOwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PhnbIerN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id p4si327604pgb.241.2019.02.21.19.47.38; Thu, 21 Feb 2019 19:47:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PhnbIerN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726737AbfBVDrI (ORCPT + 99 others); Thu, 21 Feb 2019 22:47:08 -0500 Received: from mail-it1-f195.google.com ([209.85.166.195]:54642 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725869AbfBVDrH (ORCPT ); Thu, 21 Feb 2019 22:47:07 -0500 Received: by mail-it1-f195.google.com with SMTP id f10so1193842ita.4; Thu, 21 Feb 2019 19:47:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Sk41UeLkzzTn4KypRu0CQVd69ZDRQ+8bC0EFmE/pbHI=; b=PhnbIerNCcX5NidRyPlOeUTdsCjo7mLwWPDzkV5qgR3v92UTeKiczMhJySvGGk7Zvh LimSjpLxBHIrUam49H6/TWRye3QtvdjxeT+7GPf4QBy4Rt9DJxPxABUr8pI9kBaqtD34 +4/KY6BryYYhJWIfDq3sEOZEWUUeoBOpb7ZzvzJ/IBfel1yTL/f1AX9oIsQUAMU7JgV/ IhzBRTHTiXX2xJE4RhpL6+n4Up0tt9iO3QXmSV4YlMi6p8f9PhnVlwNS+W9n0yL6vyXK lzMQfLZXqZSfNZL2gcAtICzMGOSlaWAYmMUK7FsfudnepjSLBrw79Bi73nfg8CQCtA4p LOqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=Sk41UeLkzzTn4KypRu0CQVd69ZDRQ+8bC0EFmE/pbHI=; b=amX+MoDLwf2ZmVOOuLIrdU/R+gAwtk6fzQCLfj1YX4gMzy1aHhBHe2ZbnQ3mhA3pXJ 5eFq/RqC1twzKvjMchHPqKYTdYzZNUEJ5FsK9mTaSwyLEGWPNIrHwMne5WirSg2B1umL wUGRntM04aNa3+d2CS2IMiUKW0qKCPWyEPW8eFsz7x9QHPwL6jlSQV2s+gj0siqn+/hC plc0s9EtJ8POq6ChOPZUlRFXJREn0TK6txBgjwhFtDUczaIvfKyxa+vZFA+GYL/+vW9S gc2hthFhJv5d78WvkT0jsj88EyHSwgy1XZbQ7hQZjsG79sSm2+BlyVUpwiQTDsuAeF/Z 8M6g== X-Gm-Message-State: AHQUAuajAjy3JM4tMRqnEu1G53cmzANA9bfG4MxyK3elRq1yWEazU/Pd bx6KT7Tlx/YZWsYazKh9lq4= X-Received: by 2002:a02:393:: with SMTP id e19mr1223642jae.95.1550807226605; Thu, 21 Feb 2019 19:47:06 -0800 (PST) Received: from ubu-Virtual-Machine (66-188-57-61.dhcp.bycy.mi.charter.com. [66.188.57.61]) by smtp.gmail.com with ESMTPSA id p17sm148675itp.36.2019.02.21.19.47.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Feb 2019 19:47:06 -0800 (PST) Date: Thu, 21 Feb 2019 22:47:03 -0500 From: Kimberly Brown To: Michael Kelley , Long Li , Sasha Levin , Stephen Hemminger , Dexuan Cui Cc: "K. Y. Srinivasan" , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] Drivers: hv: vmbus: Refactor chan->state if statement Message-ID: <1bb109543adc60c1f349e0c6f290591804b4289a.1550806305.git.kimbrownkd@gmail.com> References: <20190122020759.GA4054@ubu-Virtual-Machine> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The chan->state "if statement" was introduced in commit 6712cc9c2211 ("vmbus: don't return values for uninitalized channels"). That commit states that the purpose of the chan->state "if statement" is to prevent returning garbage or causing a kernel OOPS when the channel ring buffer is not initialized. The changes in this patch provide the same protection. Refactor the chan->state “if statement” in vmbus_chan_attr_show(): - Instead of checking the channel state in the "if statement", check whether the channel ring buffer pointer is NULL. Checking the ring buffer pointer makes this code consistent with hv_ringbuffer_get_debuginfo(). - Move the "if statement" to the four "_show" functions that access a channel ring buffer. Only four of the channel-level "_show" functions access a ring buffer. The ring buffer pointer does not need to be checked before calling the other "_show" functions, and moving the ring buffer pointer "if statement" to the "_show" functions that access a ring buffer makes the purpose of the "if statement" clear. Signed-off-by: Kimberly Brown --- drivers/hv/vmbus_drv.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index f290401f97e5..b02bcf1a9380 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1434,9 +1434,6 @@ static ssize_t vmbus_chan_attr_show(struct kobject *kobj, if (!attribute->show) return -EIO; - if (chan->state != CHANNEL_OPENED_STATE) - return -EINVAL; - return attribute->show(chan, buf); } @@ -1448,6 +1445,9 @@ static ssize_t out_mask_show(const struct vmbus_channel *channel, char *buf) { const struct hv_ring_buffer_info *rbi = &channel->outbound; + if (!rbi->ring_buffer) + return -EINVAL; + return sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); } static VMBUS_CHAN_ATTR_RO(out_mask); @@ -1456,6 +1456,9 @@ static ssize_t in_mask_show(const struct vmbus_channel *channel, char *buf) { const struct hv_ring_buffer_info *rbi = &channel->inbound; + if (!rbi->ring_buffer) + return -EINVAL; + return sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); } static VMBUS_CHAN_ATTR_RO(in_mask); @@ -1464,6 +1467,9 @@ static ssize_t read_avail_show(const struct vmbus_channel *channel, char *buf) { const struct hv_ring_buffer_info *rbi = &channel->inbound; + if (!rbi->ring_buffer) + return -EINVAL; + return sprintf(buf, "%u\n", hv_get_bytes_to_read(rbi)); } static VMBUS_CHAN_ATTR_RO(read_avail); @@ -1472,6 +1478,9 @@ static ssize_t write_avail_show(const struct vmbus_channel *channel, char *buf) { const struct hv_ring_buffer_info *rbi = &channel->outbound; + if (!rbi->ring_buffer) + return -EINVAL; + return sprintf(buf, "%u\n", hv_get_bytes_to_write(rbi)); } static VMBUS_CHAN_ATTR_RO(write_avail); -- 2.17.1