Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2258208rwi; Tue, 1 Nov 2022 05:51:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6AWWQaucF2ddH+mtYfKddodMHIm9bCaRiOcGg7NpJ5fi/K3HQgEadXpgj6UmpFv2/it0He X-Received: by 2002:a17:907:802:b0:781:8017:b2df with SMTP id wv2-20020a170907080200b007818017b2dfmr18134660ejb.606.1667307113322; Tue, 01 Nov 2022 05:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667307113; cv=none; d=google.com; s=arc-20160816; b=abAimSVDaSQuuxKkF4YCQhAjiKH9cfQRtVHPHjxGgpnwjBfDe/VospWc/ak2ulaT7u m+qQLn49e69rflmCjdvhQd2juykAPGqKe8bvaP/kFYb0t6hvLgeWz1qjTXS9qnWYpfSJ sfl9j/OK8/0fXPgewfHr6TKNZT7deo1wjzM2JnqmzKHBBuvQwxpHpvqD3WDcKDYs3UjD /1r/S7qee06DNsowoSLm0ga4N7YiOyMLDf9Aq0aMZL6sME2Le5kth8D3x6sVaCW7wcdP ntnV6h9wTZBTCSQQepnV3K4b+4yEhPLwy2FWJyXxtkvzD9Zqlk08DqlPJWdSOZyK7DqW PWAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Iki19jnTcou9Zt+PGjiJHIC6Xum/bucLraz87yrj9vY=; b=Xw89F/IKBN2Z18BT8a1FPmVxrUSkV2O/f/LOiUmQAYdiimWUpOLDViLIAt/CzZ/ICd u5BnHGG3iDYxRE3frTH7+IjVFP7nrUptwcfK8rRByatQ/bxeAmDWGMTEAd2P3nvWF0JV d5smLj8QPj0D9vdHOSIF/ItyI1+J4/LKvx/SFc/GAKyMCihqv2BYwHONDU1AdhBfsXCU qMhUcS9YhnoPRW6HaiEgr4ZxrKbZypuLmMzfsn2iywYXjSlGRFVE/RAnxC6LR2mx4/uG d+qJCwSAJFbmk8zxx2VSrrCKIzmNj328NCE0+YLlHxbIAgXOs0uhBYybAO+t5jEx9cpV CSWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTpEV75b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 12-20020a508e4c000000b0046190898e26si11680439edx.533.2022.11.01.05.51.28; Tue, 01 Nov 2022 05:51:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTpEV75b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbiKAL2x (ORCPT + 97 others); Tue, 1 Nov 2022 07:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbiKAL2H (ORCPT ); Tue, 1 Nov 2022 07:28:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396D8192AE; Tue, 1 Nov 2022 04:27:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D80D9B81CC6; Tue, 1 Nov 2022 11:27:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94B3BC433C1; Tue, 1 Nov 2022 11:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667302076; bh=aWWKt+ul8OJyODn7hJWxMis7sxtGLPT1ptklxe2XRB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WTpEV75bOoriK477S73KlZPt2tlhgQAZjmFRs8Vf1ol//W1F8+NyGrLA7oIS8NXPk gsqsYoUqTaXGYfmk7bmiyq1atDQKIbqRbgi8rmc/EpUXJgllLq2rhNetLpnN4eQ4Ia ARkTCwlobxRy0rkDwc+v+I7wkalxKkGdeD/bzmU5/yaC0OovV8uBL9XLjyQlcL6rZK YlYPsmuKHkamHyhg5vcOAffO8N9Gw2xYpKKYI9xPD0dE3J1QLnusiIUT47jYJfyctZ FzNmddgLimRaQAUm6MJKPTvyuMyhuL+eCwlpveBUAB/oE5SzxiQpFUhYV1k3cj9/tv sniq9QXODflCA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sakari Ailus , Bingbu Cao , Tomi Valkeinen , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 14/34] media: v4l: subdev: Fail graciously when getting try data for NULL state Date: Tue, 1 Nov 2022 07:27:06 -0400 Message-Id: <20221101112726.799368-14-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221101112726.799368-1-sashal@kernel.org> References: <20221101112726.799368-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sakari Ailus [ Upstream commit 2ba3e38517f5a4ebf9c997168079dca01b7f9fc6 ] The state argument for the functions for obtaining various parts of the state is NULL if it is called by drivers for active state. Fail graciously in that case instead of dereferencing a NULL pointer. Suggested-by: Bingbu Cao Signed-off-by: Sakari Ailus Reviewed-by: Tomi Valkeinen Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- include/media/v4l2-subdev.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 9689f38a0af1..ec1896886dbd 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1046,6 +1046,8 @@ v4l2_subdev_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL; if (WARN_ON(pad >= sd->entity.num_pads)) pad = 0; return &state->pads[pad].try_fmt; @@ -1064,6 +1066,8 @@ v4l2_subdev_get_pad_crop(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL; if (WARN_ON(pad >= sd->entity.num_pads)) pad = 0; return &state->pads[pad].try_crop; @@ -1082,6 +1086,8 @@ v4l2_subdev_get_pad_compose(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, unsigned int pad) { + if (WARN_ON(!state)) + return NULL; if (WARN_ON(pad >= sd->entity.num_pads)) pad = 0; return &state->pads[pad].try_compose; -- 2.35.1