Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6741355rwi; Mon, 24 Oct 2022 05:39:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6MvJgRSTsTH7Wfe/zMI3Bk2uP7Gtd6v51lLT4Y3eYI1R1cn1xsDzLhB/nvyHjU1ArWIpQJ X-Received: by 2002:a17:907:701:b0:780:2c44:e4dd with SMTP id xb1-20020a170907070100b007802c44e4ddmr28126421ejb.589.1666615162141; Mon, 24 Oct 2022 05:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615162; cv=none; d=google.com; s=arc-20160816; b=eqDfzr3sbaE5t1F3wq2NTEvBW6utkrDa6O09RlRYLKWyr5McLDpiTAabbAumO8gRDZ 5s+KhlNEOOimWb83VTkKlX9mmcMSNENascmUgqp8yvgqSqvuiTzIl37DK1y9DY3p+e9A IY58wLJOqo3MNZGPxvfhba+R7JuEifrmcGc2lGqtjxLSg1U09om15Aifi5J33hYeZPik phBA+2J4uTAB0E+D9ZOew9qwVlx/fsg1ao8P8w6B3oSlWdTZP07Pw5KeDeOHWbb3HVTB 5162Tvkb/wxDNvf1R/okmNCDxxF/s5o5OwDE59XoA9LX6EH76G34j5ttKmFdVfeCJbbn mEOQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f7aEdXvFCefWhKhENrMMjLEDDdlLXufN3KF5n2hG8h8=; b=IrvSwrhI5WIwO8igySWsGU2r1vJG8l7LIJXxDNCtdfEn8/nw2GVMhuzy18Z1nNZsT4 /8YkTRzSfe/go9snME57v9R2ce/paHrfhVTqI4MXlwNqEdSVpLqpbx9up8vs4DPj9nOI nOtA7zPZKI4BTCt71PHF/VkpJ3IHtyQFYz+BDnr7A2Zm+NI8RAqqyerTdFC9CTinisF5 MS7UC33OhornjK4cQnzZrJWp4Koth+yDMmIbP7cBm/QN/ci+Han8U0NOR29Ned73nYM/ 2FQJn1rTJQwKypx5zuuTumh5YqB9UXHUnOPsklx7hp5lFvyK5WfuYoRVoiUEhqSfx3sm bt8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nG4Qrm3b; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020aa7d414000000b0045915116d33si24113506edq.535.2022.10.24.05.38.49; Mon, 24 Oct 2022 05:39:22 -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=@linuxfoundation.org header.s=korg header.b=nG4Qrm3b; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbiJXMKp (ORCPT + 99 others); Mon, 24 Oct 2022 08:10:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232920AbiJXMJM (ORCPT ); Mon, 24 Oct 2022 08:09:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B73D7F103; Mon, 24 Oct 2022 04:52:34 -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 0CD44B81189; Mon, 24 Oct 2022 11:42:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60902C433D6; Mon, 24 Oct 2022 11:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611770; bh=8H+uTc4E0K4J/eQoDSzzdT79Tzi3OZ89S9QhamJF0WY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nG4Qrm3bMwubZvW7CIGhm8j+ViS5IEg4ts2wTkUNNZsPQl7yK3j4Q87phVHGMZETy 5hgYpnjb31nA2CmOxwh7mYPD52R2kOgbm2VKrUTiMWPmH3/bljH+M2T5bDw8q3OuPM Z3yL34fCF96ep8B9xuUalFSlHVkitipGPFRunl+E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niklas Cassel , Damien Le Moal , Sasha Levin Subject: [PATCH 4.9 104/159] ata: fix ata_id_sense_reporting_enabled() and ata_id_has_sense_reporting() Date: Mon, 24 Oct 2022 13:30:58 +0200 Message-Id: <20221024112953.236608165@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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: Niklas Cassel [ Upstream commit 690aa8c3ae308bc696ec8b1b357b995193927083 ] ACS-5 section 7.13.6.41 Words 85..87, 120: Commands and feature sets supported or enabled states that: If bit 15 of word 86 is set to one, bit 14 of word 119 is set to one, and bit 15 of word 119 is cleared to zero, then word 119 is valid. If bit 15 of word 86 is set to one, bit 14 of word 120 is set to one, and bit 15 of word 120 is cleared to zero, then word 120 is valid. (This text also exists in really old ACS standards, e.g. ACS-3.) Currently, ata_id_sense_reporting_enabled() and ata_id_has_sense_reporting() both check bit 15 of word 86, but neither of them check that bit 14 of word 119 is set to one, or that bit 15 of word 119 is cleared to zero. Additionally, make ata_id_sense_reporting_enabled() return false if !ata_id_has_sense_reporting(), similar to how e.g. ata_id_flush_ext_enabled() returns false if !ata_id_has_flush_ext(). Fixes: e87fd28cf9a2 ("libata: Implement support for sense data reporting") Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal Signed-off-by: Sasha Levin --- include/linux/ata.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/ata.h b/include/linux/ata.h index fdb180367ba1..8e5e7bf4a37f 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -777,16 +777,21 @@ static inline bool ata_id_has_read_log_dma_ext(const u16 *id) static inline bool ata_id_has_sense_reporting(const u16 *id) { - if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15))) + if (!(id[ATA_ID_CFS_ENABLE_2] & BIT(15))) + return false; + if ((id[ATA_ID_COMMAND_SET_3] & (BIT(15) | BIT(14))) != BIT(14)) return false; - return id[ATA_ID_COMMAND_SET_3] & (1 << 6); + return id[ATA_ID_COMMAND_SET_3] & BIT(6); } static inline bool ata_id_sense_reporting_enabled(const u16 *id) { - if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15))) + if (!ata_id_has_sense_reporting(id)) + return false; + /* ata_id_has_sense_reporting() == true, word 86 must have bit 15 set */ + if ((id[ATA_ID_COMMAND_SET_4] & (BIT(15) | BIT(14))) != BIT(14)) return false; - return id[ATA_ID_COMMAND_SET_4] & (1 << 6); + return id[ATA_ID_COMMAND_SET_4] & BIT(6); } /** -- 2.35.1