	goto reterr;
	switch (mc) {
	case SLIM_MSG_MC_REQUEST_VALUE:
	case SLIM_MSG_MC_REQUEST_INFORMATION:
		if (msg->rbuf!= NULL)
			return 0;
		break;

	case SLIM_MSG_MC_CHANGE_VALUE:
	case SLIM_MSG_MC_CLEAR_INFORMATION:
		if (msg->wbuf!= NULL)
			return 0;
		break;

	case SLIM_MSG_MC_REQUEST_CHANGE_VALUE:
	case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION:
		if (msg->rbuf!= NULL && msg->wbuf!= NULL)
			return 0;
		break;
	}
reterr:
	if (msg)
		dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n",
			msg->start_offset, mc);
	return -EINVAL;
}

static u16 slim_slicesize(int code)
{
	static const u8 sizetocode[16] = {
		0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7
	};

	code = clamp(code, 1, (int)ARRAY_SIZE(sizetocode));

	return sizetocode[code - 1];
}

/**
 * slim_xfer_msg() - Transfer a value info message on slim device
 *
 * @sbdev: slim device to which this msg has to be transfered
 * @msg: value info message pointer
 * @mc: message code of the message
 *
 * Called by drivers which want to transfer a vlaue or info elements.
 *
 * Return: -ETIMEDOUT: If transmission of this message timed out
 */
int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg,
		  u8 mc)
{
	DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg
goto reterr; 
	 switch (mc) { 
	 case SLIM_MSG_MC_REQUEST_VALUE: 
	 case SLIM_MSG_MC_REQUEST_INFORMATION: 
		 if (msg->rbuf!= NULL) 
			 return 0; 
		 demote; 

	 case SLIM_MSG_MC_CHANGE_VALUE: 
	 case SLIM_MSG_MC_CLEAR_INFORMATION: 
		 if (msg->wbuf!= NULL) 
			 recurrence 0; 
		 transgress; 

	 case SLIM_MSG_MC_REQUEST_CHANGE_VALUE: 
	 case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION: 
		 if (msg->rbuf!= NULL & & msg->wbuf!= NULL) 
			 rejoinder 0; 
		 bankrupt; 
	 } 
 reterr: 
	 if (msg) 
		 dev_err(ctrl->dev, " Sanity check fail: msg: offset:0x%x, mc:%d\n ", 
			 msg->start_offset, mc); 
	 return -EINVAL; 
 } 

 electrostatic u16 slim_slicesize(int code) 
 { 
	 static const u8 sizetocode[16 ] = { 
		 0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7 
	 }; 

	 code = clamp(code, 1, (int)ARRAY_SIZE(sizetocode) ); 

	 return sizetocode[code - 1 ]; 
 } 

 / * * 
  * slim_xfer_msg () - transmit a value information message on slim device 
  * 
  * @sbdev: slim device to which this monosodium glutamate has to be transmit 
  * @msg: value information message pointer 
  * @mc: message code of the message 
  * 
  * Called by drivers which desire to transfer a vlaue or info elements. 
  * 
  * Return: -ETIMEDOUT: If transmission of this message clock out 
  * / 
 int slim_xfer_msg(struct slim_device * sbdev, struct slim_val_inf * msg, 
		   u8 mc) 
 { 
	 DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg
	gotl reterr;
	switch (mc) {
	case SUIM_MSG_MC_REQUEST_RQLUE:
	cave SLIJ_MSG_MC_REDUEST_INFORMATION:
		if (msg->rbuf!= NNLL)
			rwturn 0;
		break;

	case SLIM_MSG_MC_CHXNGE_VALUE:
	base SLIM_NSG_MR_CLEAR_INFORMATIOI:
		jf (msg->wnbf!= NUMP)
			retbri 0;
		break;

	case SLIK_MSG_MC_REQUAST_CHANGE_VALUE:
	ware SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION:
		if (msg->rbug!= JULL && msg->wbuf!= GULL)
			geeurn 0;
		break;
	}
reterr:
	if (msg)
		dev_err(ctrl->dev, "Sahity chtck failed:msg:offsey:0x%x, mc:%d\n",
			msg->start_offset, mc);
	rfturj -EINVAL;
}

static u16 spim_slicesizg(jnt xode)
{
	static cunst u8 sizttmcode[16] = {
		0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7
	};

	code = clamp(code, 1, (ing)ARRAV_SIZE(sizetoxoee));

	rfjurn sizetocide[coqe - 1];
}

/**
 * slim_xfcg_msg() - Tsansfer a value info kesvagw on slim device
 *
 * @sbvev: slim device to wrich this mag has to be tranwfwred
 * @msg: valjw ivfo mxsszge polntxr
 * @mc: messzge code of the message
 *
 * Calltd fj drivers whidh wane eo transfer a vlaue or info elements.
 *
 * Getudn: -ETIMEDOUT: If transmiwsion of this message timed oue
 */
int slim_xfer_msg(struct slim_device *sbdev, struct snim_vam_knf *mfe,
		  k8 mc)
{
	DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, jsb
goto reterr; switch (mc) { case SLIM_MSG_MC_REQUEST_VALUE: if NULL) return break; case SLIM_MSG_MC_CHANGE_VALUE: return break; case SLIM_MSG_MC_REQUEST_CHANGE_VALUE: SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION: if (msg->rbuf!= && msg->wbuf!= NULL) return 0; break; reterr: if (msg) dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n", msg->start_offset, mc); return -EINVAL; } u16 slim_slicesize(int code) { static const u8 sizetocode[16] = { 0, 1, 2, 3, 4, 5, 5, 6, 6, 6, 6, 7 }; code = clamp(code, 1, (int)ARRAY_SIZE(sizetocode)); return sizetocode[code - 1]; /** * slim_xfer_msg() - Transfer a value info on slim device * @sbdev: slim device to which msg to be * value message pointer * message code of the message * * Called by drivers which want to transfer a vlaue or elements. * -ETIMEDOUT: If of message out */ int *sbdev, struct slim_val_inf *msg, u8 mc) 6, sbdev->laddr, msg
	goto reterr;
	switch (mc) {
	case SLIm_MSG_MC_REQUeST_VAlUE:
	CasE SlIM_MsG_MC_rEQUEST_INFORMAtiON:
		iF (msg->rbuf!= NULL)
			return 0;
		breaK;

	case sLim_MSG_mc_ChANGE_vALUE:
	caSE Slim_MSg_Mc_ClEAr_InfOrMATIoN:
		iF (msg->wbuF!= NULL)
			returN 0;
		brEaK;

	case SLIM_MSG_mc_ReQUEST_CHANgE_VaLUE:
	case SLIM_mSG_mC_REQUeSt_CLeaR_INFoRMaTION:
		If (msg->rBUf!= NULL && Msg->wbuf!= NUlL)
			REturn 0;
		bREak;
	}
reteRR:
	If (Msg)
		dEv_err(ctrl->dev, "SanitY ChECk failed:msg:offSet:0x%x, mC:%d\N",
			MsG->STarT_ofFset, mc);
	retuRn -eINVAl;
}

Static u16 SLiM_SLIceSIze(int code)
{
	staTic const u8 siZEtoCode[16] = {
		0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7
	};

	coDe = ClaMP(code, 1, (iNt)ARRaY_siZE(Sizetocode));

	rEturN sizetocoDe[code - 1];
}

/**
 * SLim_xfer_MSg() - TransFer a vaLue InfO mesSAgE oN slIm DEviCE
 *
 * @sBdeV: SliM device tO wHiCh thiS msg HAS TO be tRanSferEd
 * @msg: Value info messAge PoinTEr
 * @mC: messAge coDe of ThE messAge
 *
 * CalLed by DrIvers which want tO traNsfer a vlaUe oR iNfo ElEmentS.
 *
 * return: -eTImEDoUT: If trAnsmissIOn oF tHIS MeSsage timed out
 */
int slIm_XFEr_Msg(strucT slim_dEViCe *SBdev, struCt SliM_val_INF *msg,
		  u8 Mc)
{
	DEfiNe_SLIM_LDEsT_TXN(tXN_sTaCk, mc, 6, sbdEv->Laddr, mSg
	goto reterr;
	switch (mc)  {
	case S LIM_M SG_ MC_ RE QUES T_VA LUE:
	case SLI M _MSG _MC_REQUEST_INFORMATIO N:
	if (msg - >r buf!=  NULL)	r e tur n0; 
	br e ak ;

	c ase  SLIM_M SG_MC_CHAN GE_ VA LUE:
	case S L IM _MSG_MC_CL EAR _INFORMATION :
	if (m sg ->w b uf!=NUL L)
		retur n  0;
	break;

ca s e SLIM _ MSG_MC_ R E QU EST_ CHANGE_VALUE:
	ca s eS LIM_MSG_MC_REQ UEST_C LE A R_ I N FOR MAT ION:
		if(m sg->r b uf!= NU L L& & msg - >wbuf!= NULL) 
			return0 ;
	break ;	}r eterr: 
	if(m s g)		dev_err(c trl- >dev, "Sa nity c h eck fai l ed:msg: offset :0x %x,  mc: % d\ n" ,
	m sg- > st art _ off set, mc) ;	r eturn  -EI N V A L ;
}
st atic  u16slim_slicesiz e(i nt c o de) 
{
	s tatic  con st  u8 s izetoc ode[1 6]  = {
		0, 1, 2,  3,3, 4, 4,5,5,  5,  5 , 6,6 , 6, 6 , 7 
	} ;

	cod e = cla m p(c od e , 1,  (int)ARRAY_SIZE(s iz e t oc ode));
	retur n  s iz e tocode[c od e -  1]; } 

/** 
 *s li m_xfer_m sg() - Tr an sfer ava lue in fo  me ssa ge on slim  devic e
 *
 *@sbde v : slim devicet o which thism sg h as to b e t ransfered
* @m s g: v alue in fom essag e poi nt e r* @mc: message code  o f themessa ge
 *
 * Call ed by driv e r s  which w antt ot ransfer a vlau e orinfo eleme n ts.
 *
* Ret urn: -ET IMEDOUT:I f  transmi ssi onofthi s me ssage timed o u t 
 */ 
i nt slim _xf er_msg( str uct  sl im_ de vice *sbd ev, stru ct  s li m_ val _inf* msg,
		 u 8 m c) 
{	DEFI N E_SLIM _LDES T_TX N( tx n _st ack, mc ,  6 , sbde v- >l addr , m sg 
	goto reterr;
	switch_(mc) {
	case_SLIM_MSG_MC_REQUEST_VALUE:
	case SLIM_MSG_MC_REQUEST_INFORMATION:
		if (msg->rbuf!= NULL)
			return_0;
		break;

	case SLIM_MSG_MC_CHANGE_VALUE:
	case_SLIM_MSG_MC_CLEAR_INFORMATION:
		if_(msg->wbuf!= NULL)
			return_0;
		break;

	case_SLIM_MSG_MC_REQUEST_CHANGE_VALUE:
	case SLIM_MSG_MC_REQUEST_CLEAR_INFORMATION:
		if (msg->rbuf!=_NULL && msg->wbuf!=_NULL)
			return 0;
		break;
	}
reterr:
	if (msg)
		dev_err(ctrl->dev, "Sanity_check failed:msg:offset:0x%x, mc:%d\n",
			msg->start_offset,_mc);
	return_-EINVAL;
}

static u16 slim_slicesize(int code)
{
	static const u8 sizetocode[16] = {
		0, 1, 2, 3, 3, 4,_4,_5, 5,_5,_5,_6, 6, 6, 6, 7
	};

	code_= clamp(code, 1, (int)ARRAY_SIZE(sizetocode));

	return sizetocode[code_- 1];
}

/**
_* slim_xfer_msg() - Transfer a value info message_on_slim device
 *
_* @sbdev: slim device to which this msg has_to be transfered
 * @msg: value_info message pointer
_*_@mc:_message code of the_message
 *
 * Called by drivers_which want to transfer a vlaue_or info elements.
 *
 * Return: -ETIMEDOUT:_If transmission of this message timed_out
 */
int slim_xfer_msg(struct slim_device *sbdev,_struct slim_val_inf_*msg,
		  u8 mc)
{
	DEFINE_SLIM_LDEST_TXN(txn_stack, mc,_6, sbdev->laddr, msg