Solution by gghx.
We use the equivalent form
P(x,y):f(xy+yf(x))=xy+f(xy).
The solutions are
f(x)=xandf(x)=−x.
First, P(0,y) gives f(yf(0))=f(0) for every y. If f(0)=0, then f is constant, which is impossible in the original equation. Hence
f(0)=0.
Also,
P(x,1):f(x+f(x))=x+f(x).(1)
Suppose there is some u such that f(u)=−u. Let
a=u+f(u)=0.
By (1), f(a)=a. Substituting x=a and y/a in P gives
f(2y)=y+f(y)(2)
for every real y.
Now apply P(x,2y). Using (2), the left-hand side is
f(2y(x+f(x)))=y(x+f(x))+f(y(x+f(x))).
Using P(x,y) on the second term and then (2) on the right-hand side of P(x,2y), we get
2xy+yf(x)+f(xy)=3xy+f(xy).
Thus yf(x)=xy for all x,y, so f(x)=x for all x.
If no such u exists, then f(u)=−u for every u. Both listed functions are checked directly.