Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1530185imu; Sat, 5 Jan 2019 01:02:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vfn48DPX+wQyh8F2YeE51D9mpuySU41DlK6q9GB/Z9vqPH1y7dZQ5t7qIZDBEjquiDevjE X-Received: by 2002:a62:6204:: with SMTP id w4mr55966684pfb.5.1546678963401; Sat, 05 Jan 2019 01:02:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546678963; cv=none; d=google.com; s=arc-20160816; b=EAdU9BLFZdDc0sBeVb9YToP+WOdoqQxy6zk6A4nBBYsnGZvc1ksrADiDGCHsKlEtJH K/UhrWeGAcMZKXd9nlJtCwq1hP4tCZ9gdTvYwYwP6XCZp8hCm48VHGcThxr6t7BgUCRZ U+s9Vsk7cNLwrUdWb20pgkpUFuiagGmPGL7viSlNKi3UV+UZJA6zabQVkDANx3jzDQ5O uw+1mH91UyUMo4jwRM57qKbEGZ5t47snLnqYBzCpe5m7sotBnjNecsXm+Fol+8hRB7ZH Gt4s+VNyLjH9lvsvlPBgGCJTKtCcd3fKkSgLEIRdIbH2CuRIe7hQ8lD1bziEoJJcWLut yApQ== 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:dkim-signature; bh=E20eZVt84NzPbjrIe8iNd9rD+C4sepfhiVKGc7VgNuk=; b=nQxwhZoU0McyT/cMVMMakujK97q3XoA/W58XGLrqydIUI2uPDR7XHoxn3BhPC3Czfa 1o5HDLGvNG2MHrR6RD3gPqBPd802wbBaBBMtMWcbCblfo4qk8FPUObcFrmBtMqgQV5/2 glPcw23HmjBtxgsYsII/Kk1wPiKIHZKMdpZZwCY5Q+cuG43weA5Ix8NePQ1GQ7eLJsFU LzAZFD9S5xnFS7/y5+4aCU8/HKjkBiL5j4OltXb4oDv6zDiK+z/OCq1wrGr9lvkxD45T Qi6JOwnoETpDuS+adWGCs60wCLEnhRWgTtvaZGnmT3itXXAZCocJ3fb4bCOIB+tli1Nk /D9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KiJlk6l5; 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 p14si57595706pfi.12.2019.01.05.01.02.27; Sat, 05 Jan 2019 01:02:43 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=KiJlk6l5; 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 S1726224AbfAEJAY (ORCPT + 99 others); Sat, 5 Jan 2019 04:00:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:60740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfAEJAY (ORCPT ); Sat, 5 Jan 2019 04:00:24 -0500 Received: from localhost (unknown [62.119.166.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4890208E3; Sat, 5 Jan 2019 09:00:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546678823; bh=7Vw1Dpl/s2e2TFSQ38mOHUKz/LJHMz5gJ6lOp6i+lhA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KiJlk6l5Tg9F4EsIoic7OTq/c13NrOkOvwuaxKq6fTdlFHEbF1TBTZtSqWP8u4SAx tzblgTX6ZH44kxFXEKL+pj+DhLN9IGstMct2CW3XqWJf0EpNAdoxHUmGH6Yt0evQ49 y1/ygGBL7S2LAmm3QAhsq/IHjrgxtUUlV9cPI7JE= Date: Sat, 5 Jan 2019 10:00:19 +0100 From: Greg KH To: rkir@google.com Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] drivers: misc: goldfish_address_space: add a driver Message-ID: <20190105090019.GC13941@kroah.com> References: <20190104021311.38194-1-rkir@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190104021311.38194-1-rkir@google.com> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 03, 2019 at 06:13:11PM -0800, rkir@google.com wrote: > +static int as_release(struct inode *inode, struct file *filp) > +{ > + struct as_allocated_blocks *allocated_blocks = filp->private_data; > + struct as_device_state *state; > + int blocks_size; > + int i; > + > + WARN_ON(!allocated_blocks); > + WARN_ON(!allocated_blocks->state); > + WARN_ON(!allocated_blocks->blocks); > + WARN_ON(allocated_blocks->blocks_size < 0); > + > + state = allocated_blocks->state; > + blocks_size = allocated_blocks->blocks_size; > + > + if (mutex_lock_interruptible(&state->registers_lock)) I just took this chunk of code as an example of what you do all over this file. Please do not use WARN_ON() as a lazy way of saying "I have no idea how to handle this random error that might happen, so I'm going to punt to the user and crash the machine." If these things really can happen, then properly check for them and handle the error correctly. If they can not, then just remove the WARN_ON check as it is not needed at all. As it is, this code is obviously broken because if allocated_blocks->state is NULL, you just crashed on the line after the check. So even if you did somehow want to "warn" for something like this happening, you did not handle it and killed the machine. All of the WARN_ON can be removed here as I bet you are testing for things that can never happen. And if it could happen, then properyl test for it. as-is, this code is not ok at all. Also, along these lines, who else is reviewing this code before you send it out? Surely you are not reyling on just me to do that, you are taking advantage of the huge numbers of reviewers inside your company that could have told you this before posting it, right? Please do so. greg k-h