From patchwork Mon Jun 3 15:25:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13683920 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AA7612CDBA for ; Mon, 3 Jun 2024 15:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717428373; cv=none; b=mHpZZ//qaYSiAZkTUMUl+UCynn6uAbkEg9sw+zmAdmoE0BI51LwZQPJgSLB8v0vu14meeVcqUKOic0i6SrcLLuTTZtLg2Zu4FrlgPhG7cigS1p1AkwThWkBi70QGPkBVBK7k+5OmK/cy6igss0sz6zaECeShTK7kzTREmRZo9+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717428373; c=relaxed/simple; bh=tiJLXtDkSIMar4/Di3c82hBxDKnQveLEddpdC0yDe40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ln6NhVGZk1CxguTc9hGvSwp3k5YEeJhKi+M1mA2Eupdvqu+tj8LrRuibmNwYZsHCnAQNCvVk4nh8aVjAGT0os2CfRRSUKkK5cDNxwHeUIMa/zQMfofXnKlqtlLVLm0anT6aOx6dZFWlgzAZtgn1v02s3fBLFfmig8Wsd07DQuFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=H61bxHfG; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H61bxHfG" Received: from localhost.localdomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DC454908; Mon, 3 Jun 2024 17:25:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717428357; bh=tiJLXtDkSIMar4/Di3c82hBxDKnQveLEddpdC0yDe40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H61bxHfG0zO7sn9unKgA7ngkzaOzhTUCZwUyBJBctFqMrwZaMhdfftHs95BtJhuSO F1vPW2NpOgS0XZrzByVAd3YkyNDXQkMkbkRI/okHDRgJeLjmCMSL2idQd7Ph6NvTic lqmQW+2sZFJC6+VR3Ilg8xFxJYdCt3/mtHevMHqk= From: Jacopo Mondi To: Hans Verkuil , Laurent Pinchart , Sakari Ailus Cc: Jacopo Mondi , Linux Media Mailing List Subject: [RFC 1/3] media: videobuf2: WARN if !vb2_queue.buf_ops Date: Mon, 3 Jun 2024 17:25:45 +0200 Message-ID: <20240603152548.107158-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> References: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The videobuf2 framework unconditionally set 'struct vb2_queue.buf_ops' to 'v4l2_buf_ops' in vb2_queue_init_name() and does not allow drivers to overwrite it. The framework then assumes all 'buf_ops' operations to be present and valid. To prepare for allowing drivers to override the 'buf_ops' members implementation but still guarantee all members are correctly populated and valid, WARN() if any of the 'buf_ops' operations is not available in the function call wrappers. Signed-off-by: Jacopo Mondi --- drivers/media/common/videobuf2/videobuf2-core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index b6bf8f232f48..8ceae97a0f08 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -187,15 +187,19 @@ module_param(debug, int, 0644); #define call_bufop(q, op, args...) \ ({ \ int ret = 0; \ - if (q && q->buf_ops && q->buf_ops->op) \ - ret = q->buf_ops->op(args); \ + if (q) { \ + if (!WARN_ON(!q->buf_ops) && !WARN_ON(!q->buf_ops->op)) \ + ret = q->buf_ops->op(args); \ + } \ ret; \ }) #define call_void_bufop(q, op, args...) \ ({ \ - if (q && q->buf_ops && q->buf_ops->op) \ - q->buf_ops->op(args); \ + if (q) { \ + if (!WARN_ON(!q->buf_ops) && !WARN_ON(!q->buf_ops->op)) \ + q->buf_ops->op(args); \ + } \ }) static void __vb2_queue_cancel(struct vb2_queue *q);