Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp194131imu; Wed, 12 Dec 2018 14:54:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/XvhTDHmQXzXBeaPb9wL11NQ2m4RLUK4ck5adFkw/1/udzuzDhzhQJghbt9j1N0R+lJKMIz X-Received: by 2002:a62:2292:: with SMTP id p18mr22537693pfj.9.1544655247105; Wed, 12 Dec 2018 14:54:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544655247; cv=none; d=google.com; s=arc-20160816; b=pr+Cou8RZro/NNUhrttrlw0Ztjf30I5ik8rOcESiS+UyVMMiQ0ti3XN3tDs54F+ii7 oWphU0jijzmUsFRxSown53pjhmqIO6AbgOyaWmWuYN9fw12GVRD/uLL6u3c64HWLthkd Ubvgy6+K3eS/8uoYkaXsqrInSBQu4BU6/cvHQbwjszKhnMOfgu0hsDUmNQc7ubDwZfpK nAYPLy1geQFeGhxMvvw/6v69drVozM2JRXrQKZPpIdOsFEoXM0u7HeT1gYfweDzULYoG BzRqtEExdO4UJmG4WaEOUqmNBx2Xx/cM2ns+4TY5jbdsVjWtk7tq2U5Vb6bGqheQfLYb LVWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to; bh=tDA1TNgEirIoraAB2EOG97yG1fQTO1N5dMYhRHrYBDc=; b=vpkKNuG6m3p+BMGBMDaX/5dG+Zm99tGLww6gB7ZyZpDFJrQGwdr1FljG1oO8Uf3Wl5 zIs4j65iAHv1eKVvjSH70QM+QH4bR00zddmN6krkD9dwyec5rOySndmUgxp4jAmNbdFu QbOrmcXqKBM5+f4zr8hDmnSKqgf6NC36gxFoZ7yW7fX69bSwtqflEYb+ZPEnbb0icDKS 8RMv3pD/REpUTS7a9+EIlWdcEtRNFuSev6fuf8N0C+rBGxeqCLCI7wjB76k7jdHFkvFd RPcqmvm9Q3M3/Cafq5hF2mLotOXwOn5pcjlwTuQ0aGpOqqxIg4psFV16+kmxbnUNtYw+ Xy6A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f81si87203pfh.33.2018.12.12.14.53.52; Wed, 12 Dec 2018 14:54:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728420AbeLLWwy (ORCPT + 99 others); Wed, 12 Dec 2018 17:52:54 -0500 Received: from ale.deltatee.com ([207.54.116.67]:51194 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbeLLWwy (ORCPT ); Wed, 12 Dec 2018 17:52:54 -0500 Received: from guinness.priv.deltatee.com ([172.16.1.162]) by ale.deltatee.com with esmtp (Exim 4.89) (envelope-from ) id 1gXDN4-00018k-BX; Wed, 12 Dec 2018 15:52:51 -0700 To: Bjorn Helgaas , Wesley Sheng Cc: kurt.schwemmer@microsemi.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, wesleyshenggit@sina.com References: <1544433144-7563-1-git-send-email-wesley.sheng@microchip.com> <1544433144-7563-4-git-send-email-wesley.sheng@microchip.com> <20181212224315.GK99796@google.com> From: Logan Gunthorpe Message-ID: <0e8da614-dd78-5e41-df25-ec1b037ef4d7@deltatee.com> Date: Wed, 12 Dec 2018 15:52:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20181212224315.GK99796@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-CA Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 172.16.1.162 X-SA-Exim-Rcpt-To: wesleyshenggit@sina.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kurt.schwemmer@microsemi.com, wesley.sheng@microchip.com, helgaas@kernel.org X-SA-Exim-Mail-From: logang@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [PATCH 3/5] switchtec: A temporary variable should be used for the flags of switchtec_ioctl_event_ctl X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-12-12 3:43 p.m., Bjorn Helgaas wrote: > On Mon, Dec 10, 2018 at 05:12:22PM +0800, Wesley Sheng wrote: >> From: Joey Zhang >> >> For nr_idxs is larger than 1 switchtec_ioctl_event_ctl event flags will be >> used by each event indexes. In current implementation the event flags are >> overwritten by first call of the function event_ctl(). >> >> Preserve the event flag value with a temporary variable. >> >> Fixes: 52eabba5bcdb ("switchtec: Add IOCTLs to the Switchtec driver") >> Signed-off-by: Joey Zhang >> Signed-off-by: Wesley Sheng >> Reviewed-by: Logan Gunthorpe >> --- >> drivers/pci/switch/switchtec.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c >> index 480107e..a908670 100644 >> --- a/drivers/pci/switch/switchtec.c >> +++ b/drivers/pci/switch/switchtec.c >> @@ -796,6 +796,7 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev, >> { >> int ret; >> int nr_idxs; >> + unsigned int event_flags; >> struct switchtec_ioctl_event_ctl ctl; >> >> if (copy_from_user(&ctl, uctl, sizeof(ctl))) >> @@ -817,7 +818,9 @@ static int ioctl_event_ctl(struct switchtec_dev *stdev, >> else >> return -EINVAL; >> >> + event_flags = ctl.flags; >> for (ctl.index = 0; ctl.index < nr_idxs; ctl.index++) { >> + ctl.flags = event_flags; >> ret = event_ctl(stdev, &ctl); > > event_ctl() overwrites several other things, in addition to ctl.flags: > > ctl.data[] > ctl.occurred > ctl.count > > Is that what you intend? It looks like only the values from the *last* > call of event_ctl() will be copied back to the user buffer. Yeah, it's just SWITCHTEC_IOCTL_EVENT_IDX_ALL is perhaps a strange abuse of the interface. The intention being that if you are querying information about an event you'd use it's specific index. If you are trying to set flags you can set them for all event of a specific type at once using IDX_ALL. Looking at it now it looks pretty ugly (and I'm not sure what I was thinking when I wrote it). But it's what we have and this patch fixes a bug where we aren't actually enabling/disabling all events when that's what the user is asking for. Logan