Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp4131225imc; Thu, 14 Mar 2019 13:06:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXRwt+yCizLi72sdTy+HmUD3PHg4f1DUO+xCzUuJymRmZo4DTHbZKyt+912JwXwZ4Tw4sL X-Received: by 2002:a63:ea48:: with SMTP id l8mr46053321pgk.431.1552593961114; Thu, 14 Mar 2019 13:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552593961; cv=none; d=google.com; s=arc-20160816; b=GqomOFAoPHeo7Bgzh7e82zAJrvGJyW3MUsDgz4L5d4C37LqSCsWdBd2sUV9zotzQoi rgVb4V5Xn/5lhUdHKqPq7G6jiM2lG1K33aGgCEsT5CXf92D1FoCrrrykAO4E1Wq0xrTt v8ZGZUAVxgyT021dCd9Y+xCz1Ff902UI8o/d2b/67JHaS95QbVPvwFOJK/XB0ce01Z5/ DuwQIrqF/xjXxTfyfTNyYzuozrHeEzk+iVJ6IlDz2/NjdPBYHLaMgnRT7YCYR6k8i+p9 cXAf/3G3zwLZEdbZnTVY9/MvP5FTLYd/ljTWC9EvIMoQa46O2MGoQEG70VxGX+eOB6ln zA8w== 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=Wp80+44UXTvBPR/J8XZ3iMpuK3pkq3Zm7DfnTwZPdLE=; b=Yqcm3qgW84M2sAjA2kq3+tk412EuWvudnZ+n3ipVwlV5Efaq7l4kauoON57WX91//Z ufinN5Fh3Ypxc3nKIxfpWHhbDLaUS/7o3QH62bgT36rHNYU2hKVjHkr2sK9rX+hdiuBs QFRNPOeBdCTnSDrFn6EnJKrxUX/lvgb8p4nANEOSmNLIz7OA+wgn6OWZk0E5pVSC01Zn UGhzQjZ4TTJKH0pC2EErcWWlwzPvGTDnAxlSFiGibzgW42eTA9MK1cm1fi8HavB09BQX WIXlR3fWB3Un7s98t16KlWTb1Fz8HAiwnNWpUe3ybpVLDG6yb8bSB2IIAd25oOmjvg2m zDeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=exYUW6Hj; 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 y11si13824087plk.323.2019.03.14.13.05.46; Thu, 14 Mar 2019 13:06:01 -0700 (PDT) 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=exYUW6Hj; 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 S1727687AbfCNUFF (ORCPT + 99 others); Thu, 14 Mar 2019 16:05:05 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:51698 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfCNUFF (ORCPT ); Thu, 14 Mar 2019 16:05:05 -0400 Received: by mail-it1-f196.google.com with SMTP id e24so6756941itl.1; Thu, 14 Mar 2019 13:05:04 -0700 (PDT) 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=Wp80+44UXTvBPR/J8XZ3iMpuK3pkq3Zm7DfnTwZPdLE=; b=exYUW6Hj+2ZNKqs1phgx8NJ53TnESHzjVYoTDXHlWA1NQppEtSlEnw9QHHz4rSy7qd +tkqWIIo/tDYgwx/gCYvWmWZ4+o+2RfmdYWCPUFNfEAB3FgcnMr9jCXHCWBwVGvHy3py gU0TXViySqQVbLcqyMUpKkGwBPUFUhBUH5A8ouELCNz+5971kr+lrRSIzu6Y3Pxp4l6X 8ldxqmFzkyWr6G25P8I1Y4CwCSb3VrXqgziuGb8o1bPEjqDMvHmFERwgTwhLa+cvlhXi soaQrXv98KeftfccIFceWh/88GYUdyN/uYCZBaQmKXjVynZx6AlJJ3WIRhh/eBimXV6n /qCQ== 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=Wp80+44UXTvBPR/J8XZ3iMpuK3pkq3Zm7DfnTwZPdLE=; b=csi4W1aOq6fw+iYnN3OIHi3mx+jpN+xALoCW3RjyZURsIw0ydU7y9qY0j9DpDCthxh 0T+16/x9ZIPVf/gVDsFgosxpHdm2AYBhkqZ3UvhKBTRpCHvchpRFldeMricoMTjxd62t x+Jvu36VjkfTAOzaZVDwjLmQJ820zBWdiK7q4L6xSPkn88IDcbPPQq41yPWPGrzojsL0 iGrhJmcglHmcTSWS8GK89w8G6L0Os3EmTwIq1pJHycZdbxB4+Qkq3zQJ6PWKAh3EPWJD nIHoFxIgP6ouQgI2WsWAXs8x4twoaw4PVr+yD9Rnbbx59faHjEFqhR/YB5oeOha4F3Ht 3EVw== X-Gm-Message-State: APjAAAWjFpMGneAp1BF2sKO2dGtZLnylDGaUG2umZ09YGLAzTzG6r0TQ 6diXbaovdhjjHxwVslHhKgMTKFkA X-Received: by 2002:a02:6206:: with SMTP id d6mr57957jac.84.1552593903773; Thu, 14 Mar 2019 13:05:03 -0700 (PDT) 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 m23sm5006622ioh.29.2019.03.14.13.05.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 13:05:02 -0700 (PDT) Date: Thu, 14 Mar 2019 16:05:00 -0400 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 v3 1/3] Drivers: hv: vmbus: Refactor chan->state if statement Message-ID: References: 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 Reviewed-by: Michael Kelley --- 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 a7bb709870a8..7f15c41d952e 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1435,9 +1435,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); } @@ -1449,6 +1446,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); @@ -1457,6 +1457,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); @@ -1465,6 +1468,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); @@ -1473,6 +1479,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