Consider a function $f=f(x,y)$, with $df=u\ dx+v\ dy$, and we want the Legendre transformation $g=f-ux$, with $dg=df-u\ dx-x\ du=\color{red}{u\ dx}+v\ dy\color{red}{-u\ dx}-x\ du=v\ dy-x\ du$ (eliminating the dependence with $x$), then $g=g(u,y)$.
I don't understand why this works, since we have, in principle, that $g=g(x,y,u)=f(x,y)-ux$, but if $g$ doesn't depends on $x$, then $\partial g/\partial x$ must be zero: \begin{equation} \frac{\partial g}{\partial x}=\color{red}{\frac{\partial f}{\partial x}-u}-\frac{\partial^2 f}{\partial^2 x}x=-\frac{\partial^2 f}{\partial^2 x}x=0 \end{equation} (Since $\frac{\partial f}{\partial x}=u$) But why is $-\frac{\partial^2 f}{\partial^2 x}x=0$? Clearly I'm missing something here, I will appreciate your help.