From patchwork Mon Oct 8 14:52:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10630911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFD7C13BB for ; Mon, 8 Oct 2018 14:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE0AB295A3 for ; Mon, 8 Oct 2018 14:52:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C01FB29571; Mon, 8 Oct 2018 14:52:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 715E429571 for ; Mon, 8 Oct 2018 14:52:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9A40589FAD; Mon, 8 Oct 2018 14:52:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3782689FAD for ; Mon, 8 Oct 2018 14:52:25 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id a85-v6so12225180qkg.3 for ; Mon, 08 Oct 2018 07:52:25 -0700 (PDT) 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:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=i3VL7enVUB8mmUR8iuBXBuDcOmQd/t6YsKyhYNxMpxE=; b=CTrQsfViOEqI1xBvDlGOWc4ZS/IEyuGoFbAwFVLiF/EXIFEBf2gAWjGEKlPbFkcDJK b5VipdLxA2GLpdxne1Y7Gj0Dgwr4RPqRbzdvc3URzPt5csisX8WiAbXNNZJWq1Fiu0Q7 KD6b/sCbDGNNV8axGdJL8BgnmwOzkA8P5DDAq34zUyuK+bUrmMQt7JIqIQoWMQKqGh3i lWwsDAFyrGFttHCB2Dwoz2jcFpYjpsnLV30dT2LxKQ8E7Nn9YdpIVwz/m/XSxYo3nd62 gYsQgOs2ALGN1dPw/E+p2I9oUZuK5Exyb8QdWy5wql/wuITOhvdChQ3fkFwbVdeehJ/5 1fpA== X-Gm-Message-State: ABuFfohp8zwLR3M7s35kXOno6y8A0QDyU3mpyypYljITSzDrbH61NtZ5 unoocs2IZS8iWxaIRB2BreHDAhpYbCw= X-Google-Smtp-Source: ACcGV62OQyzwTqg067hnjclUlglCwh6o0qarFHJ7KD32zB1yRH6kBNAOWAGJrqnYxjer0dj42qQOzg== X-Received: by 2002:ae9:e507:: with SMTP id w7-v6mr18760728qkf.246.1539010344305; Mon, 08 Oct 2018 07:52:24 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id m54-v6sm4045414qtb.97.2018.10.08.07.52.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 07:52:23 -0700 (PDT) Date: Mon, 8 Oct 2018 11:52:20 -0300 From: Rodrigo Siqueira To: Gustavo Padovan , Maarten Lankhorst , Sean Paul , David Airlie , Daniel Vetter Subject: [PATCH] drm/drm_vblank: Change EINVAL by the correct errno Message-ID: <20181008145220.p34dllgsiw6rlpod@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180716 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP For historical reason, the function drm_wait_vblank_ioctl always return -EINVAL if something gets wrong. This scenario limits the flexibility for the userspace make detailed verification of the problem and take some action. In particular, the validation of “if (!dev->irq_enabled)” in the drm_wait_vblank_ioctl is responsible for checking if the driver support vblank or not. If the driver does not support VBlank, the function drm_wait_vblank_ioctl returns EINVAL which does not represent the real issue; this patch changes this behavior by return ENOTTY (Inappropriate ioctl for device). Additionally, some operations are unsupported by this function, and returns EINVAL; this patch changes the return value to EOPNOTSUPP (Operation not supported). Lastly, the function drm_wait_vblank_ioctl is invoked by libdrm, which is used by many compositors; because of this, it is important to check if this change breaks any compositor. In this sense, the following projects were examined: * Drm-hwcomposer * Kwin * Sway * Wlroots * Wayland-core * Weston * Xorg (67 different drivers) For each repository the verification happened in three steps: * Update the main branch * Look for any occurrence "drmWaitVBlank" with the command: git grep -n "drmWaitVBlank" * Look in the git history of the project with the command: git log -SdrmWaitVBlank Finally, none of the above projects validate the use of EINVAL which make safe, at least for these projects, to change the return values. Signed-off-by: Rodrigo Siqueira --- drivers/gpu/drm/drm_vblank.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 98e091175921..88ec6fb49afb 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1533,10 +1533,10 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data, unsigned int flags, pipe, high_pipe; if (!dev->irq_enabled) - return -EINVAL; + return -ENOTTY; if (vblwait->request.type & _DRM_VBLANK_SIGNAL) - return -EINVAL; + return -EOPNOTSUPP; if (vblwait->request.type & ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK | @@ -1545,7 +1545,7 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data, vblwait->request.type, (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK | _DRM_VBLANK_HIGH_CRTC_MASK)); - return -EINVAL; + return -EOPNOTSUPP; } flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK;