Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1485753yba; Sat, 27 Apr 2019 00:02:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLjUO9tLZebEZ3mTECAztSinrxIuPj5eEnBpavq79TUXuitfLDqN1pC2XAa9C4bRgfF968 X-Received: by 2002:aa7:96eb:: with SMTP id i11mr30347365pfq.229.1556348572682; Sat, 27 Apr 2019 00:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556348572; cv=none; d=google.com; s=arc-20160816; b=X0QegL6jB4cGxuug/WzVSgDVTVs5eIZPJgAjOnfvWLk5vdMtsQfNqbo/p0/n9vOYeb frFcvpwOcPvjm6Hia4XjDvU/vk64gBsLI94uJFMxf+uN+QMVkfaUJUxFl3bBVkX9zM54 9cdr17y9PaAeT0jdTXHWgCKpuPTxNFPcJZIdPv+/Kqyc+c1aIAvVmKRak3NvQtwpRaS+ h0ZqalqtABAmzv7fuPUFreD21M7oYSJKPsQetnZHe2SKg4pklDZ5VUEpM1IT1AbcqxuA ppT5mDbcQsTod3tdgDrzDZh71kAL3ciMaLwDPQajJOTWLl15R6u6grQGdppK+AJGjpCj h1VA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=w8T7ZSiMApNZ17UaYFAffvssRkBxhn+tAzLXX+UHjvA=; b=Ap+G/dezJ6/MrbB6LqyccFraWlm5c66MZSYyLLZki6b/4eLhsbv6IBqtXhK5Dnj9Cs JNXNzNekhBXdzXk7mTzzJJqZL519aWJt6HE0W99udpGHtTUtOTxsB4synP7HM0x8pV8t C6CiuGr2JidjuEGLkbEjlShBN1wl9SryUZSbKSSgyU2sVXsd/aR2Ynh5jLEeItVoX/36 BSMFvE0CRUI/DtHCyJ3eNFhqEIiWuuVNI00A9KrU/2JLRer6HSXQGkUTFsKUrjwyADSx WJgRRfRSNyAQsZoLqxEfeX5uA8BHlRuxnVaF2Em4D9MTb0o1MYAF9yjqoogYD9HhnH1W tc0Q== 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 a17si26799444plm.25.2019.04.27.00.02.37; Sat, 27 Apr 2019 00:02:52 -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; 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 S1726377AbfD0HBN (ORCPT + 99 others); Sat, 27 Apr 2019 03:01:13 -0400 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:57926 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbfD0HBN (ORCPT ); Sat, 27 Apr 2019 03:01:13 -0400 Received: by mail.osadl.at (Postfix, from userid 1001) id 1D7A85C1337; Sat, 27 Apr 2019 09:00:21 +0200 (CEST) Date: Sat, 27 Apr 2019 09:00:21 +0200 From: Nicholas Mc Guire To: Sven Van Asbroeck Cc: Nicholas Mc Guire , Greg Kroah-Hartman , devel@driverdev.osuosl.org, Linux Kernel Mailing List Subject: Re: [PATCH RFC] staging: fieldbus: anybus-s: use proper type for wait_for_completion_timeout Message-ID: <20190427070021.GA2290@osadl.at> References: <1556339208-7722-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 27, 2019 at 02:17:42AM -0400, Sven Van Asbroeck wrote: > Hello Nicholas, thank you for your contribution, I really appreciate it ! > See inline comments below. > > On Sat, Apr 27, 2019 at 12:32 AM Nicholas Mc Guire wrote: > > > > wait_for_completion_timeout() returns unsigned long (0 on timeout or > > remaining jiffies) not int. > > Nice catch ! > > > thus there is no negative case to check for > > here. > > The current code can only break if wait_for_completion_timeout() > returns an unsigned long large enough to make the "int ret" turn > negative. This could result in probe() returning a nonsensical error > value, even though the wait did not time out. > > Fortunately that currently cannot happen, because TIMEOUT > (2*HZ) won't overflow an int. ok - thats benign then - never the less since code tends to get copied it would be good to make it comply with API spec > > That being said, this return value type mismatch should definitely > be fixed up. > > > > > Signed-off-by: Nicholas Mc Guire > > --- > > > > Problem located with experimental API conformance checking cocci script > > > > Q: It is not really clear if the proposed fix is the right thing here or if > > this should not be using wait_for_completion_interruptible - which would > > return -ERESTARTSYS on interruption. Someone that knows the details of > > this driver would need to check what condition should initiate the > > goto err_reset; which was actually unreachable in the current code. > > It's used in probe(), so no need for an interruptible wait, AFAIK. > It can stay as-is. > > > > > Patch was compile-tested with. x86_64_defconfig + FIELDBUS_DEV=m, > > HMS_ANYBUSS_BUS=m > > (some unrelated sparse warnings (cast to restricted __be16)) > > That sounds interesting too. Could you provide more details? make C=1 drivers/staging/fieldbus/anybuss/host.c:1350:25: warning: cast to restricted __be16 drivers/staging/fieldbus/anybuss/host.c:1350:25: warning: cast to restricted __be16 drivers/staging/fieldbus/anybuss/host.c:1350:25: warning: cast to restricted __be16 drivers/staging/fieldbus/anybuss/host.c:1350:25: warning: cast to restricted __be16 drivers/staging/fieldbus/anybuss/host.c:1350:25: warning: cast to restricted > > > > > - ret = wait_for_completion_timeout(&cd->card_boot, TIMEOUT); > > - if (ret == 0) > > + time_left = wait_for_completion_timeout(&cd->card_boot, TIMEOUT); > > + if (time_left == 0) > > ret = -ETIMEDOUT; > > - if (ret < 0) > > - goto err_reset; > > NAK. This does not jump to err_reset on timeout. > > May I suggest the following instead ? (manual formatting) > > - ret = wait_for_completion_timeout(&cd->card_boot, TIMEOUT); > - if (ret == 0) > - ret = -ETIMEDOUT; > - if (ret < 0) > - goto err_reset; > + if (!wait_for_completion_timeout(&cd->card_boot, TIMEOUT)) { > + ret = -ETIMEDOUT; > + goto err_reset; > + } Ah - ok - that was the bit missing for me ! how that goto branch would be reached or if it should be dropped as it had not been reachable in the past. I'll send the V2 later today then. thx! hofrat