From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0066.outbound.protection.outlook.com [104.47.41.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0F6D421E49BA7 for ; Tue, 22 Aug 2017 08:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=+2eYeqJTgjWcQ6FjxTBBiyP/nv8Rjo/pkDx+2194nYM=; b=O0UcLZoI7Y9MHPv5muNEc6Z0bMP95h18G6Mtq4mx9cU8kziKeaSM2ZB4n22M9n38ZzbNzBruhTQq+F9KflEGOVyxgR3WirC2VxWg5CLQSQV5k/Ify/vinrVv/39qCBYazYaxWdQrctcwrOGAn+58m5mWtWXBPkJsH3ItN1O239A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from [10.236.136.62] (165.204.77.1) by DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1362.18; Tue, 22 Aug 2017 15:44:39 +0000 Cc: brijesh.singh@amd.com, Jordan Justen , Tom Lendacky , Ard Biesheuvel To: Laszlo Ersek , edk2-devel@lists.01.org References: <1502710605-8058-1-git-send-email-brijesh.singh@amd.com> <1502710605-8058-17-git-send-email-brijesh.singh@amd.com> From: Brijesh Singh Message-ID: Date: Tue, 22 Aug 2017 10:44:35 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR11CA0016.namprd11.prod.outlook.com (2603:10b6:405:2::26) To DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9d9855d8-188d-4149-05fe-08d4e974b387 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM2PR12MB0156; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 3:tO0OUJPJua8FnMr0izNHcVM9iVEEkSYbOYB+qQvexqBeMbcDFVmqMnkWs1j5xuWCCWmd1St90Uul+CBO3nBM3tW5U19FWjfSMGUuXK1EqShaYgYR5578R3GmWUNTk9aTrhPFCSvHeprnBV6cybX3C5cp/qFw5zfBBywMyRxu/cWn02MF5JN3HAj98lN9jSmXLcezT48riVu0gR7rhX3IfeliIFDi3Y6oniY6J2PaczB3bDpBNv1OCJzCAK9A/evW; 25:yXVQk8P0ZR6kcRVnXGfuUGYy4s2phl3XyR+9gl+/jKElU4cA5eUk9oUMBOvZ0Tb+miokyS/eWVIstGuqxeV/Xz5KyENd7VJgoBr2e105KjYiuYR27e3Zp4YLtPP4JN9kU/re/fsX7vIylsm/n5kNxwle0KnsSXFZWpnLQyC02lapi1izCbmi17gqInqqH4AMqMmO2NMtZGeA8i+JCYCvaWvtI1Zi4nlvs6GTUk7wxtHPdH1Pvsi90XyysW+MsR8v9g0C4E33xolbzYpqm0o0MKfR2ZRHhpa2zddcQneVUAEDbcpF7PI/Q+KIUUAhkZADecKNbaQ6xiZ623c146bYXQ==; 31:0SDF5arM9qZ7iWtf5mrlUnobhflZUVhv8jKI0adwuyP/G9DAZR4K9yD1PQMiiK1QsSfM/iOkh9+TSuBpg80o509J70DOBEyAl0rAw/6EH4nUjYpWoTAie4sk7aMa/ySdV4UqR8D+8f00BYTr37+gagQAwwx49AAd4lv07qUmF186zj0M1hde5VYBAZk7AMrs+EV59HNumOvwFOTuvFPuKHJq7ew4ZEvBNnM/9TqYQMw= X-MS-TrafficTypeDiagnostic: DM2PR12MB0156: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:2rxZEbR8gCLaqqDnuIaNsYJK/6lHbTS7rkUI8ZyYxgUjPH2VlqjdSyP5/2ZQh8AZpSZf+sXenMPiSuQyWl99bVFRYJ0EhZXPr/T7pXHCTFEJIac55VrGnV+R9ZWnIMUIXo8AKssn8bwNqyIGCNhtCsvFHa2vXqrodgg4XNbkmSnxO6FGV2AYF78MSBCGG8XX2WuDW0WXYHsdP2AGD1hLgw92Oxytv9o5k+ZDWySxzlK+MgVPr5yNxCkQKMTHSw9AI1d6KEgNYazGwQvtaUKUHBkh5w72or4uQ6IksliVbUuTjnuG+0KFIkyuUZ0W4u8jgshYaELtEYyeeYBsl0UeDqG6JcdXQdlTjYU+o1+m4yAi0PDvPNydeWCoYZzcf4hxcSIEmyy3L6fWpmtEGlFMwiY+Z/lYBNwJzxHpuIMFY8+p/AwHK5xGYPaq8L6n7LA+yHc9Nf9LScj76lt3KpZZzAn6kVhDDGoL6Zh8SUPLwpgZlVWLo/FlpJreBYDw7CE1; 4:hHa20qHOONNelsn9j38ZY+R6m1DtZJUmQACjFRqVw0/hehbEJ4zJ3F0pibHGd7UNt+4U/2aCIwOhxUEE1cqW4ZCvSpvJ39IW067TJYyPisOI59sPXdrh5XlsRlnvf+bAtssuwAo+bqph/HRr+KBrva9O5teVKjkVX2kUJxuOsOBGwVwzdILbmNhxScIvUv7UfdHnqCsYM/OJnhtZ/V8O4NKoB8vWFv5g4dsXp0quIDzEn/K8lAm4J6xJesZf5S3TEI5e2DIQmy48tAtwo//MhcAHrU34XP9B72UvtHenJWw= X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123564025)(20161123560025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0156; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0156; X-Forefront-PRVS: 04073E895A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6049001)(6009001)(39860400002)(377454003)(189002)(199003)(24454002)(50986999)(230700001)(106356001)(478600001)(76176999)(54356999)(6116002)(101416001)(6666003)(2950100002)(8676002)(2906002)(3846002)(23676002)(189998001)(65806001)(42186005)(81166006)(81156014)(33646002)(31686004)(31696002)(966005)(36756003)(229853002)(53546010)(66066001)(65956001)(25786009)(110136004)(64126003)(65826007)(305945005)(7736002)(4326008)(5660300001)(97736004)(54906002)(4001350100001)(47776003)(50466002)(6306002)(77096006)(7350300001)(6486002)(6246003)(83506001)(68736007)(105586002)(53936002)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0156; H:[10.236.136.62]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTJQUjEyTUIwMTU2OzIzOnllR1JDb1N4TXhGUnVKWnE3MTh5WE9JeFhs?= =?utf-8?B?VlZxcWRaV09QMG9LdE84RTZGZlB1TDUxRTZ4cm9UQS96cC9rcVJWeG9sNGgv?= =?utf-8?B?VzhFQkFTK0FIRFJKZ1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H1YPRYrRJaFzhg7K3N6gIzitw+HI0kpIhNwEY3NuZ7EBwsfWghJhJjqGgTR0JpPZFY2FOP9fmdcUFBnbZzx15j6b8vZY6fMpCzdUrWSW4lv0cA25fSNhVf1qO6Gcu6vpgkdwEdDynoiyr5FMq9DknmiSBM0msGDs8Kauh3cxoH5YeghBHUf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2017 15:44:39.7437 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0156 Subject: Re: [PATCH v2 16/23] OvmfPkg/VirtioRngDxe: map host address to device address X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Aug 2017 15:42:09 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/21/2017 09:05 AM, Laszlo Ersek wrote: [...] > >> for (Index = 0; Index < RNGValueLength; Index++) { >> RNGValue[Index] = Buffer[Index]; >> } >> Status = EFI_SUCCESS; >> >> + // >> + // Buffer is already Unmaped(), goto free it. >> + // >> + goto FreeBuffer; > > (6) We restrict "goto" statements to error handling: > > https://edk2-docs.gitbooks.io/edk-ii-c-coding-standards-specification/content/5_source_files/57_c_programming.html > >> 5.7.3.8 Goto Statements should not be used (in general) >> [...] >> It is common to use goto for error handling and thus, exiting a >> routine in an error case is the only legal use of a goto. [...] > > So please open-code the FreePool() call and the "return" statement here. > I was wondering if something like this is acceptable ? Actually since we need to handle the Unmap due to error from VirtioFlush hence I was trying to minimize the adding new state variables or additional checks inside the for loop. @@ -178,17 +194,34 @@ VirtioRngGetRNG ( if (VirtioFlush (Dev->VirtIo, 0, &Dev->Ring, &Indices, &Len) != EFI_SUCCESS) { Status = EFI_DEVICE_ERROR; - goto FreeBuffer; + goto UnmapBuffer; } ASSERT (Len > 0); ASSERT (Len <= BufferSize); } + // + // Unmap the device buffer before accessing it. + // + Status = Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping); + if (EFI_ERROR (Status)) { + goto FreeBuffer; + } + for (Index = 0; Index < RNGValueLength; Index++) { RNGValue[Index] = Buffer[Index]; } Status = EFI_SUCCESS; +UnmapBuffer: + // + // If we are reached here due to the error then unmap the buffer otherwise + // the buffer is already unmapped after VirtioFlush(). + // + if (EFI_ERROR (Status)) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping); + } + FreeBuffer: FreePool ((VOID *)Buffer); return Status;