@ -1,4 +1,4 @@
/* Copyright (c) 2014-2019 , The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2020 , The Linux Foundation. All rights reserved.
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License version 2 and
@ -153,6 +153,8 @@ void diag_md_close_device(int id)
* When we close the Memory device mode , make sure we flush the
* internal buffers in the table so that there are no stale
* entries .
* Give Write_done notifications to buffers with packets
* indicated valid length .
*/
spin_lock_irqsave ( & ch - > lock , flags ) ;
for ( j = 0 ; j < ch - > num_tbl_entries ; j + + ) {
@ -168,9 +170,37 @@ void diag_md_close_device(int id)
entry - > ctx = 0 ;
}
spin_unlock_irqrestore ( & ch - > lock , flags ) ;
diag_ws_reset ( DIAG_WS_MUX ) ;
}
void diag_md_clear_tbl_entries ( int id )
{
int j ;
unsigned long flags ;
struct diag_md_info * ch = NULL ;
struct diag_buf_tbl_t * entry = NULL ;
ch = & diag_md [ id ] ;
if ( ! ch | | ! ch - > md_info_inited )
return ;
/*
* When we close the Memory device mode , make sure we flush the
* internal buffers in the table so that there are no stale
* entries .
*/
spin_lock_irqsave ( & ch - > lock , flags ) ;
for ( j = 0 ; j < ch - > num_tbl_entries ; j + + ) {
entry = & ch - > tbl [ j ] ;
entry - > buf = NULL ;
entry - > len = 0 ;
entry - > ctx = 0 ;
}
spin_unlock_irqrestore ( & ch - > lock , flags ) ;
diag_ws_reset ( DIAG_WS_MUX ) ;
}
int diag_md_write ( int id , unsigned char * buf , int len , int ctx )
{
int i , peripheral , pid = 0 ;
@ -302,13 +332,18 @@ int diag_md_copy_to_user(char __user *buf, int *pret, size_t buf_size,
if ( ! ch - > md_info_inited )
continue ;
for ( j = 0 ; j < ch - > num_tbl_entries & & ! err ; j + + ) {
spin_lock_irqsave ( & ch - > lock , flags ) ;
entry = & ch - > tbl [ j ] ;
if ( entry - > len < = 0 | | entry - > buf = = NULL )
if ( entry - > len < = 0 | | entry - > buf = = NULL ) {
spin_unlock_irqrestore ( & ch - > lock , flags ) ;
continue ;
}
peripheral = diag_md_get_peripheral ( entry - > ctx ) ;
if ( peripheral < 0 )
if ( peripheral < 0 ) {
spin_unlock_irqrestore ( & ch - > lock , flags ) ;
goto drop_data ;
}
spin_unlock_irqrestore ( & ch - > lock , flags ) ;
session_info =
diag_md_session_get_peripheral ( i , peripheral ) ;
if ( ! session_info )