From patchwork Fri Jan 15 01:31:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 8037301 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C5A9BBEEE5 for ; Fri, 15 Jan 2016 01:32:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E384B2051C for ; Fri, 15 Jan 2016 01:32:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F13C620513 for ; Fri, 15 Jan 2016 01:32:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360AbcAOBcJ (ORCPT ); Thu, 14 Jan 2016 20:32:09 -0500 Received: from mga14.intel.com ([192.55.52.115]:21756 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751289AbcAOBcI (ORCPT ); Thu, 14 Jan 2016 20:32:08 -0500 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 14 Jan 2016 17:32:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,297,1449561600"; d="scan'208";a="29651739" Received: from omniknight.lm.intel.com ([10.232.112.171]) by fmsmga004.fm.intel.com with ESMTP; 14 Jan 2016 17:32:06 -0800 From: Vishal Verma To: linux-nvdimm@lists.01.org Cc: Vishal Verma , linux-acpi@vger.kernel.org, Dan Williams , Linda Knippers Subject: [PATCH 1/3] badblocks: add null checks for bb in the badblocks api Date: Thu, 14 Jan 2016 18:31:54 -0700 Message-Id: <1452821516-26788-2-git-send-email-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452821516-26788-1-git-send-email-vishal.l.verma@intel.com> References: <1452821516-26788-1-git-send-email-vishal.l.verma@intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The move from gendisk wrappers for badblocks functions to directly using them meant we lost some checks for !disk->bb Re-add those checks into the badblocks functions so all users get the checks. Signed-off-by: Vishal Verma --- block/badblocks.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/block/badblocks.c b/block/badblocks.c index 7be53cb..aa5e0a1 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -68,6 +68,9 @@ int badblocks_check(struct badblocks *bb, sector_t s, int sectors, sector_t target = s + sectors; unsigned seq; + if (!bb) + return 0; + if (bb->shift > 0) { /* round the start down, and the end up */ s >>= bb->shift; @@ -156,7 +159,7 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors, int rv = 0; unsigned long flags; - if (bb->shift < 0) + if (!bb || bb->shift < 0) /* badblocks are disabled */ return 0; @@ -321,6 +324,9 @@ int badblocks_clear(struct badblocks *bb, sector_t s, int sectors) sector_t target = s + sectors; int rv = 0; + if (!bb) + return 0; + if (bb->shift > 0) { /* When clearing we round the start up and the end down. * This should not matter as the shift should align with @@ -415,7 +421,7 @@ EXPORT_SYMBOL_GPL(badblocks_clear); */ void ack_all_badblocks(struct badblocks *bb) { - if (bb->page == NULL || bb->changed) + if (!bb || bb->page == NULL || bb->changed) /* no point even trying */ return; write_seqlock_irq(&bb->lock); @@ -451,11 +457,13 @@ ssize_t badblocks_show(struct badblocks *bb, char *page, int unack) { size_t len; int i; - u64 *p = bb->page; + u64 *p; unsigned seq; - if (bb->shift < 0) - return 0; + if (!bb || bb->shift < 0) + return sprintf(page, "\n"); + + p = bb->page; retry: seq = read_seqbegin(&bb->lock); @@ -504,6 +512,9 @@ ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len, int length; char newline; + if (!bb) + return -ENXIO; + switch (sscanf(page, "%llu %d%c", §or, &length, &newline)) { case 3: if (newline != '\n')