From patchwork Thu May 20 17:01:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 12271023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C399C433ED for ; Thu, 20 May 2021 17:03:53 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1F85E61006 for ; Thu, 20 May 2021 17:03:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F85E61006 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=NTd8KaZAe+CHt0iIbuOQ38JJqi1Cyfh5xTmtMCkE8Q0=; b=IkXahBRYi0RI/PX/fx4cLkB+xh EPEmz+7E791TcfETo2/03hMDrJ0pjHIlOdTgjIqOaKRZfV84/V5VS+MaVsgLja2VTx1lMhSQrJgdB pnUkdTpYIozYxvtgCR8eaha9MeKh4wgLTujQxY7+i4L50/D3BR35m5fQ+aQhghrV70I4YKYCp95fF 3YS9oBLssCNwTFsj0f44UWa12MX/H3BCqvuKXl4KkLBmQL6SLgdeXf5SDeRzWMnmZ02h6L3OwXisi OUD2z1nNxBP+3ah6bGXm1V4RhTgFuUYnPUlIoTQ5kHQoB5xZbivjcCSeuZhf7Ejb7enq3CUQrGQOq mBr4cS0w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljm3j-0022A9-E3; Thu, 20 May 2021 17:02:07 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljm3b-00228x-4U for linux-arm-kernel@desiato.infradead.org; Thu, 20 May 2021 17:01:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=GnCcM4kag0zi75Uj3XnSUlN1BTLRGuzOS27Epni0zmo=; b=erAxvbkvEl2D9GR6fbdsnN9WWa OQrykEx4aCzcuX+f2h9Q+D9EH8c3xmhh1ABV20+JpFfxWPIx9WgtzqTiQqdxyTNicQwXRVyZZQAVQ +LAUrkwsmUoXdtpJthvGcRdy9fjuVg+s7adz0M5iIe6c9p0NqCZ188JtP99kzeOO8U2+4lpAAxmVi IC6lzktYjy6x3AVXfQnOjj+shy6tm8wTBXEvojB9lIHA+PPX0slL8JexSl3NIUPurCylyBply21CL 9MgLW2cLyhyXTUrLCsb1kcuPXCTGPd2SrROoqZxyXCenqWIsaj8a15Ml29fGwq8NABjhlKIgTlMI/ 7au6nw4g==; Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljm3Y-00GWtD-Ic for linux-arm-kernel@lists.infradead.org; Thu, 20 May 2021 17:01:57 +0000 Received: by mail-qk1-x731.google.com with SMTP id f18so16881831qko.7 for ; Thu, 20 May 2021 10:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GnCcM4kag0zi75Uj3XnSUlN1BTLRGuzOS27Epni0zmo=; b=eak30O+kEa209QuEDAZAJMFUbuAf2bsnMkD8l28owJBdDM/gZzDyLdO6bbWJTTHFBs A/OoRkWEINWzols+VuxAtmCddsz6VIaJGwfcEAveNenaOTEg8QJ7XH0eD+El4ZEYmJe3 5X6h1rS6gpu/aqmZhEXJwcXWQf/DhXGzVP99D4obEySNIGPfWg9u8QtJXsxHOQx4OD8r tqrOQJrz9pZNNfsgJEb/hM/ULv5nSidgffjAAkXAn79jnNpetxan/l/WW4+hv121+A7r wjmygZ7y70h7nqBJuic3ByMxT0A6m7wD1LB8kEfisi33s4BD0ZhMnQwnQztTG3a+AaK6 Teqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=GnCcM4kag0zi75Uj3XnSUlN1BTLRGuzOS27Epni0zmo=; b=HUY3THPP21P4kCdNHooHFN+wwrwYL9PlmAHvDhVsH5ICrpOEAMVrAJI6+ym3rw8pxD XesBAGSo1V+WKppg1lvwSG7wJgwT6Q8T1Fp5P52qNMmiL8+z7CjQpseUh9rsa2/tDt8D 5ISrsFTR4Q9UygSUzq5WeHkzaZ5MippzyKYQWSwN+36JX7r9Syi5HeI83dWyknU3Gyo1 3Eu5ifgACkyeahKcnifjcMyftrtEjc4eSGOCe3H0tRZ9zk58x8vSNV9zUBEprZ0nZXHb dqzVWIdmw26v8G9oNuYsXawy9pNndiZ0P7IZDQ0NJps9gvzvvf78C+Q71dOsmhRKZ8Ip FOTA== X-Gm-Message-State: AOAM532XXtE2qzh2Qdv15tBwFHbRphtzSrB5dBhzo2Klvf8GohXEOqVF NSL/OEt3eNstutoDs7ZMsPg= X-Google-Smtp-Source: ABdhPJz11VyJYws//1N5g3k2MC2R6i3xdtq9pyvWSXk86cGaGETPxPxkxvumfeOimd/jIXh5ADP8hA== X-Received: by 2002:a37:9b51:: with SMTP id d78mr6195648qke.441.1621530114179; Thu, 20 May 2021 10:01:54 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id y8sm2312647qtn.61.2021.05.20.10.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 10:01:53 -0700 (PDT) From: Guenter Roeck To: Derek Kiernan Cc: Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Michal Simek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [RFC PATCH] misc: xilinx-sdfec: Check if file->private_data is NULL Date: Thu, 20 May 2021 10:01:50 -0700 Message-Id: <20210520170150.1615956-1-linux@roeck-us.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210520_100156_630383_E744B4C8 X-CRM114-Status: GOOD ( 15.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org container_of() only returns NULL if the passed pointer is NULL _and_ the embedded element is the first element of the structure. Even if that is the case, testing against it is misleading and possibly dangerous because the position of the embedded element may change. Explicitly check if the parameter is NULL and bail out if so instead of checking the result of container_of(). Signed-off-by: Guenter Roeck Acked-by: Dragan Cvetic --- RFC: The NULL check in the poll function is likely unnecessary. Interestingly, there is no NULL check in the ioctl function, even though there is a similar container_of() in that function. However, I do not feel comfortable enough to change the functionality of this code and drop the check entirely. drivers/misc/xilinx_sdfec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c index 23c8448a9c3b..0a3721d31dea 100644 --- a/drivers/misc/xilinx_sdfec.c +++ b/drivers/misc/xilinx_sdfec.c @@ -1011,11 +1011,11 @@ static __poll_t xsdfec_poll(struct file *file, poll_table *wait) __poll_t mask = 0; struct xsdfec_dev *xsdfec; - xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev); - - if (!xsdfec) + if (!file->private_data) return EPOLLNVAL | EPOLLHUP; + xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev); + poll_wait(file, &xsdfec->waitq, wait); /* XSDFEC ISR detected an error */