From patchwork Fri Jul 31 13:05:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6911261 Return-Path: X-Original-To: patchwork-linux-scsi@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 0196DC05AC for ; Fri, 31 Jul 2015 13:05:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 081E22063B for ; Fri, 31 Jul 2015 13:05:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 218F720618 for ; Fri, 31 Jul 2015 13:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752353AbbGaNFH (ORCPT ); Fri, 31 Jul 2015 09:05:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:54746 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751000AbbGaNFG (ORCPT ); Fri, 31 Jul 2015 09:05:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D283EAD4F; Fri, 31 Jul 2015 13:05:04 +0000 (UTC) From: Hannes Reinecke To: James Bottomley Cc: Christoph Hellwig , linux-scsi@vger.kernel.org, Hannes Reinecke , Hannes Reinecke Subject: [PATCH] scsi: Fixup fixed sense generation Date: Fri, 31 Jul 2015 15:05:03 +0200 Message-Id: <1438347903-106697-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.2 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-8.3 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 Fixed sense reserves only 32 bits for the 'information' field, so we need to restrict the 'information' value to avoid sense data corruption. Also the sense key is only 4 bits. Signed-off-by: Hannes Reinecke --- drivers/scsi/scsi_error.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 106884a..ba7ffc4 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2510,13 +2510,13 @@ void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq) { if (desc) { buf[0] = 0x72; /* descriptor, current */ - buf[1] = key; + buf[1] = key & 0x0f; buf[2] = asc; buf[3] = ascq; buf[7] = 0; } else { buf[0] = 0x70; /* fixed, current */ - buf[2] = key; + buf[2] = key & 0x0f; buf[7] = 0xa; buf[12] = asc; buf[13] = ascq; @@ -2549,7 +2549,11 @@ void scsi_set_sense_information(u8 *buf, u64 info) put_unaligned_be64(info, &ucp[4]); } else if ((buf[0] & 0x7f) == 0x70) { buf[0] |= 0x80; - put_unaligned_be64(info, &buf[3]); + /* + * Fixed format sense reserves only 32 bits for the + * 'information' field + */ + put_unaligned_be32((u32)info, &buf[3]); } } EXPORT_SYMBOL(scsi_set_sense_information);